Post

Replies

Boosts

Views

Activity

Reply to NWConnection (web-socket) does not disconnect when server disconnects gracefully
Sure, I will open a TSI next week. Meanwhile, continuing my investigation, I looked into console logs and I can see SSL3_RT_ALERT, description: close notify. Which means Mac client is receiving TLS close but is not closing the connection. The screenshot for console log is available here: https://ibb.co/bXYrPT4 The server side calls SSL_shutdown which only closes the write direction from server side while keeping read side open. SSL_shutdown() only closes the write direction. It is not possible to call SSL_write() after calling SSL_shutdown(). The read direction is closed by the peer. So, as per the OpenSSL docs, server is doing right thing but NWConnection is not responding back with notify close, to finish the connection from both sides.
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’21
Reply to NWConnection (web-socket) does not disconnect when server disconnects gracefully
Hi @eskimo, After our discussion last evening, we did some deliberations and now we are able to get FIN from server to client. However, we still notice that NWConnection does not close the connection after receiving FIN and subsequent writes are being sent to server. Is there any reason NWConnection is not closing web-socket after receiving FIN and ACKing to the FIN? Our server has separate management of read and write web sockets. They are sending FIN after closing their write socket while keeping their read socket open for a little while longer so that client can write any last message or send FIN and close. Could there be any reason/configuration for NWConnection to not disconnect by writing client FIN after receiving server FIN? In Windows client, we see client side FIN after server FIN and then connection closes completely. The packet capture screenshot with server FIN can be seen https://ibb.co/M6cLz85 since image upload here was failing.
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’21
Reply to NWConnection (web-socket) does not disconnect when server disconnects gracefully
Here is the code we use for reading data continuously on web socket. We only stop reading only when we encounter an error. func listen() {         connection?.receiveMessage { [weak self] (data, context, _, error) in             guard let self = self else {                 return             }             if let data = data, !data.isEmpty, let context = context {                 self.receiveMessage(data: data, context: context)             }             if let error = error {                 self.reportErrorOrDisconnection(error)             } else {                 self.listen()             }         }     }
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’21
Reply to NWConnection (web-socket) does not disconnect when server disconnects gracefully
Sure, I will open a TSI next week. Meanwhile, continuing my investigation, I looked into console logs and I can see SSL3_RT_ALERT, description: close notify. Which means Mac client is receiving TLS close but is not closing the connection. The screenshot for console log is available here: https://ibb.co/bXYrPT4 The server side calls SSL_shutdown which only closes the write direction from server side while keeping read side open. SSL_shutdown() only closes the write direction. It is not possible to call SSL_write() after calling SSL_shutdown(). The read direction is closed by the peer. So, as per the OpenSSL docs, server is doing right thing but NWConnection is not responding back with notify close, to finish the connection from both sides.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to NWConnection (web-socket) does not disconnect when server disconnects gracefully
Hi @eskimo, After our discussion last evening, we did some deliberations and now we are able to get FIN from server to client. However, we still notice that NWConnection does not close the connection after receiving FIN and subsequent writes are being sent to server. Is there any reason NWConnection is not closing web-socket after receiving FIN and ACKing to the FIN? Our server has separate management of read and write web sockets. They are sending FIN after closing their write socket while keeping their read socket open for a little while longer so that client can write any last message or send FIN and close. Could there be any reason/configuration for NWConnection to not disconnect by writing client FIN after receiving server FIN? In Windows client, we see client side FIN after server FIN and then connection closes completely. The packet capture screenshot with server FIN can be seen https://ibb.co/M6cLz85 since image upload here was failing.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to NWConnection (web-socket) does not disconnect when server disconnects gracefully
Here is the code we use for reading data continuously on web socket. We only stop reading only when we encounter an error. func listen() {         connection?.receiveMessage { [weak self] (data, context, _, error) in             guard let self = self else {                 return             }             if let data = data, !data.isEmpty, let context = context {                 self.receiveMessage(data: data, context: context)             }             if let error = error {                 self.reportErrorOrDisconnection(error)             } else {                 self.listen()             }         }     }
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21