title: What does "error in connection_block_invoke_2: Connection interrupted" mean?
body: <h2>Problem</h2>
  
  <p>I recently updated my iPhone to iOS 10.3.1 and Xcode to Version 8.3.2. Currently, I have an app which runs a few <code>URLRequest</code>s once my app launches. </p>
  
  <p>However, after updating both iOS and Xcode, the app occasionally return an error message:</p>
  
  <blockquote>
    <p>error in connection_block_invoke_2: Connection interrupted</p>
  </blockquote>
  
  <p>The message is quite vague but I assumed it has something to do with the <code>URLRequest</code>s since it mentions "Connection interrupted".</p>
  
  <p>Whenever this error message appears, it will "freeze" the app for ~5s before getting the data from the server.</p>
  
  <hr>
  
  <h2>Question</h2>
  
  <p><strong>So, what does this error message actually mean? And how can I minimise it or fix it?</strong></p>
  
  <hr>
  
  <h2>Example of one <code>URLRequest</code>:</h2>
  
  <pre><code>func checkLogin () {
      let username = txtUsername.text!
      let password = txtPassword.text!
  
      let post = "username=\(username)&amp;password=\(password)"
      NSLog("PostData: %@",post);
      let url:URL = URL(string:"https://example.com/login.php")!
      let postData = post.data(using: .utf8)!
      let postLength = String( postData.count )
      var request = URLRequest(url: url)
  
      request.httpMethod = "POST"
      request.httpBody = postData
      request.setValue(postLength as String, forHTTPHeaderField: "Content-Length")
      request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
      request.setValue("application/json", forHTTPHeaderField: "Accept")
      let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
          if error != nil {
              return
          }
          if let jsonData = (try? JSONSerialization.jsonObject(with: data!, options: [])) as? [String:Any] {
              let success = jsonData["success"] as! Int
              if success == 1 {
                  //do something,
              }
              else {
                  //show alert
              }
          }
  
      })
      task.resume()
  }
  </code></pre>
  
  <hr>
  
  <h2>Duplicates</h2>
  
  <p><strong>The following questions <em>does not</em> solve my problem as:</strong></p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/27372330/what-is-error-in-connection-block-invoke-2-connection-interrupted-in-ios">What is &quot;error in __connection_block_invoke_2: Connection interrupted&quot; in iOS?</a></p>
  
  <ul>
  <li>I didn't receive any memory warning so the answer does not apply.</li>
  </ul></li>
  <li><p><a href="https://stackoverflow.com/questions/30651171/ios-error-in-connection-block-invoke-2-connection-interrupted">iOS: error in __connection_block_invoke_2: Connection interrupted</a></p>
  
  <ul>
  <li>I didn't use <code>AVCaptureMovieFileOutput</code> and <code>AVCaptureVideoDataOutput</code> at all in my app, thus the answer also doesn't apply.</li>
  </ul></li>
  <li><p><a href="https://stackoverflow.com/questions/38964320/error-in-connection-block-invoke-2-connection-interrupted-on-ipad">error in __connection_block_invoke_2: Connection interrupted on iPad</a> &amp; <a href="https://stackoverflow.com/questions/34280176/xcode-7-error-message-error-in-connection-block-invoke-2-connection-interrup">Xcode 7 error message &quot;error in __connection_block_invoke_2: Connection interrupted&quot; when app runs on iPad</a></p>
  
  <ul>
  <li>No answer at all.</li>
  </ul></li>
  </ul>