title: Not connecting to RPC server in release mode, but works fine in debug mode
body: <p>I have a command line app that does the following:</p>
  
  <ul>
  <li>downloads an RSS feed with torrent links</li>
  <li>stores it in a sqlite database and tags them as "added" or "ignored"</li>
  <li>connects to a transmission server (in my local network)</li>
  <li>loads items from sqlite marked as "added" and adds to transmission server</li>
  </ul>
  
  <p>The above works fine in debug mode. However, when I build for release and try to run directly or from launchd, it always times out. The most relevant code is in <code>main.swift</code> which goes below.</p>
  
  <pre class="lang-swift prettyprint-override"><code>private func getTransmissionClient() -&gt; Transmission? {
          let client = Transmission(
              baseURL: serverConfig.server,
              username: serverConfig.username,
              password: serverConfig.password)
  
          var cancellables = Set&lt;AnyCancellable&gt;()
  
          let group = DispatchGroup()
          group.enter()
          print("[INFO] Connecting to client")
          client.request(.rpcVersion)
              .sink(
                  receiveCompletion: { _ in group.leave() },
                  receiveValue: { rpcVersion in
                      print("[INFO]: Successfully Connected! RPC Version: \(rpcVersion)")
              })
              .store(in: &amp;cancellables)
          let wallTimeout = DispatchWallTime.now() +
              DispatchTimeInterval.seconds(serverConfig.secondsTimeout ?? 15)
          let res = group.wait(wallTimeout: wallTimeout)
  
          if res == DispatchTimeoutResult.success {
              return client
          } else {
              return nil
          }
  
      }
  
      public func updateTransmission() throws {
  
          print("[INFO] [\(Date())] Starting Transmission Update")
  
          let clientOpt = getTransmissionClient()
          guard let client = clientOpt else {
              print("[ERROR] Failed to connect to transmission client")
              exit(1)
          }
  
          var cancellables = Set&lt;AnyCancellable&gt;()
  
          let items = try store.getPendingDownload()
          print("[INFO] [\(Date())] Adding \(items.count) new items to transmission")
  
          let group = DispatchGroup()
          for item in items {
  
              let linkComponents = "\(item.link)".components(separatedBy: "&amp;")
              assert(linkComponents.count &gt; 0, "Link seems wrong")
  
              group.enter()
              client.request(.add(url: item.link))
                  .sink(receiveCompletion: { completion in
                      if case let .failure(error) = completion {
                          print("[Failure] \(item.title)")
                          print("[Failure] Details: \(error)")
  
                      }
                      group.leave()
                  }, receiveValue: { _ in
                      print("[Success] \(item.title)")
                      do {
                          try self.store.update(item: item, with: .downloaded)
  
                      } catch {
                          print("[Error] Couldn't save new status to DB")
                      }
                  })
                  .store(in: &amp;cancellables)
          }
  
  
          let wallTimeout = DispatchWallTime.now() +
              DispatchTimeInterval.seconds(serverConfig.secondsTimeout ?? 15)
          let res = group.wait(wallTimeout: wallTimeout)
          if res == DispatchTimeoutResult.success {
              print("Tasks successfully submitted")
          } else {
              print("Timed out")
              exit(1)
          }
      }
  </code></pre>
  
  <p>Oddly enough, the code seemed to work fine before I added the database. The DispatchGroup was already there, as well as the Transmission-Swift client. I guess something that I did is being "optimized away" by the compiler? This is just speculation though after seeing some other questions on StackOverflow, but I am still not clear on it.</p>
  
  <p>I am using macOS 10.15 and Swift 5.2.2.</p>
  
  <p>Full code available in <a href="https://github.com/ataias/TorrentRSS/tree/f0f0166d0aac887aaa7bf5a4245f34913c2dc927" rel="nofollow noreferrer">github</a> (link to specific commit that has the bug)</p>