URLSessionUploadTask getting automatically cancelled instantly

前端 未结 3 1835
心在旅途
心在旅途 2020-12-17 20:49

I\'m having this weird issue in which a newly created URLSessionUploadTask gets cancelled instantly. I\'m not sure if it\'s a bug with the current beta of Xcode

3条回答
  •  心在旅途
    2020-12-17 21:31

    Your server is broken..

    tcp_connection_cancel 1
    nw_socket_handle_socket_event Event mask: 0x4
    nw_socket_handle_socket_event Socket received WRITE_CLOSE event
    nw_endpoint_handler_cancel [1 anilist.co:443 ready resolver (satisfied)]
    nw_endpoint_handler_cancel [1.1 104.28.1.44:443 ready socket-flow (satisfied)]
    __nw_socket_service_writes_block_invoke sendmsg(fd 9, 31 bytes): socket has been closed
    nw_endpoint_flow_protocol_error [1.1
    104.28.1.44:443 cancelled socket-flow (null)] Socket protocol sent error: [32] Broken pipe
    nw_endpoint_flow_protocol_disconnected [1.1 104.28.1.44:443 cancelled socket-flow (null)] Output protocol disconnected
    nw_endpoint_handler_cancel [1.2 104.28.0.44:443 initial path (null)] 
    nw_resolver_cancel_on_queue 0x60800010da40
    [NWConcrete_tcp_connection dealloc] 1
    [User Defaults] CFPrefsPlistSource<0x6180000f8700> (Domain: XIO.PrivateAPITest, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null)) is waiting for writes to complete so it can determine if new data is available
    

    It waits infinitely for "writes" to complete..

    It sends the request.. does the SSL handshake and gets no response. It times out and considers it a broken request..

    class WTF : NSObject, URLSessionDelegate {
    
        var urlSession: URLSession!
    
        override init() {
            super.init()
    
            urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
    
            var request = URLRequest(url: URL(string: "https://anilist.co/api/auth/access_token?client_secret=REMOVED&grant_type=authorization_code&redirect_uri=genericwebsitethatshouldntexist.bo&client_id=ibanez-hod6w&code=REMOVED")!)
            request.httpMethod = "POST"
    
            let data = try! JSONSerialization.data(withJSONObject: ["Test":"Test"], options: [])
    
            urlSession.uploadTask(with: request, from: data).resume()
        }
    
        func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
    
            completionHandler(.performDefaultHandling, nil)
    
        }
    
        func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
    
        }
    
        func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: NSError?) {
    
        }
    
        func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: (URLRequest?) -> Void) {
    
            completionHandler(request)
    
        }
    
        func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: (URLSession.ResponseDisposition) -> Void) {
    
            completionHandler(.allow)
    
        }
    
        func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
    
        }
    }
    

提交回复
热议问题