If you view the tcp traffic with Wireshark, it might help corroborate your theory. Maybe you can see FIN from both sides and that would confirm your thinking. ??
— jrj > On Jan 17, 2018, at 2:22 PM, Jens Alfke <j...@mooseyard.com> wrote: > > I’m using NSURLSessionStreamTask to implement a WebSocket client. About half > the time when I close the connection, my delegate callback gets an error > ENOTCONN. As far as I can tell, this error is bogus: there seems to be a race > condition where both the server and the client are closing the socket, and > sometimes when CFNetwork closes the socket it’s already been marked as > closed, hence the error. > > The sequence of events looks like: > 1. I send a WebSocket CLOSE message > 2. Something logs the message "TIC TCP Conn Missing Error [2:0x610000033d40]: > Generating 1:54” > 3. I receive the confirming CLOSE message from the server > 4. Something logs "TIC Read Status [2:0x610000033d40]: 1:57” > 5. I call -closeWrite and -closeRead on the NSURLSessionStreamTask > 6. My -URLSession:readClosedForStreamTask: and > -URLSession:writeClosedForStreamTask: delegate methods are called > 7. My -URLSession:task:didCompleteWithError: delegate method is called, with > an error {NSPOSIXErrorDomain, 57, “Socket is not connected”}. (57 = ENOTCONN.) > > The other half of the time it goes exactly the same way except that in the > last step the error parameter is nil. > > As I said, I believe this error is bogus, so I’m updating my delegate method > to ignore this specific error if I’ve already closed the streams. But I’d > like to make sure my analysis and workaround are correct. > > —Jens > > PS: Running on macOS 10.13.2, and building with Xcode 9.2. > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/macnetworkprog/jrj%40apple.com > > This email sent to j...@apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com This email sent to arch...@mail-archive.com