I'm trying to implement a web socket communication using NSURLSessionWebSocket. We should support also iOS 13 devices. The strange debug message appears on iOS 13.7 systems.
My code is in objective-c. The main use case is, that the client sends a request and it is waiting for some messages from the server, which can arrive at any time, let's say in the close future. For this, after calling the:
I start to listen to the server response, and when it arrives I restart the listening:
This works fine. Sometimes I have to close the socket if something is happening, so I call the:
The socket closing also works good, because the
delegate method is called with the right values so the socket is closed at this point.
So everything works as expected, except that right after calling the close method a strange "simulated crash" message appears on the console, but the application continues to work and apparently everything is okay with it:
This happens only on iOS 13.7 systems, apparently on iOS 14.4 I get only the last message:
which seems to be legit.
I think the problem is that I close the socket during the socket listening ("receiveMessage") is active. But honestly I think that should not be a problem, because I expect to be able to close anytime a socket, even if I'm trying to read something from it.
My question would be, can I ignore this "simulated crash" or is it possible, that it will make some problems in different cases? Or is my approach good, to call the message receiving method continuously and to close simply the socket when it is needed? Anybody faced the same problem?
My code is in objective-c. The main use case is, that the client sends a request and it is waiting for some messages from the server, which can arrive at any time, let's say in the close future. For this, after calling the:
Code Block [self.webSocketTask resume];
I start to listen to the server response, and when it arrives I restart the listening:
Code Block - (void)startMessageReceiving { [self.webSocketTask receiveMessageWithCompletionHandler:^(NSURLSessionWebSocketMessage * _Nullable message, NSError * _Nullable error) { ... if( error != nil ) { ... handleError return ; } ... Process the arrived message [self startMessageReceiving]; }];
This works fine. Sometimes I have to close the socket if something is happening, so I call the:
Code Block [self.webSocketTask cancelWithCloseCode:code reason:reasonData];
The socket closing also works good, because the
Code Block - (void)URLSession:(NSURLSession *)session webSocketTask:(NSURLSessionWebSocketTask *)webSocketTask didCloseWithCode:(NSURLSessionWebSocketCloseCode)closeCode reason:(NSData *)reason {
delegate method is called with the right values so the socket is closed at this point.
So everything works as expected, except that right after calling the close method a strange "simulated crash" message appears on the console, but the application continues to work and apparently everything is okay with it:
Code Block [] __nwlog_err_simulate_crash simulate crash already simulated "nw_content_context_copy_protocol_metadata called with null context" [] nw_content_context_copy_protocol_metadata called with null context, dumping backtrace: [x86_64] libnetcore-1880.120.4 0 libnetwork.dylib 0x00000001203a91f8 __nw_create_backtrace_string + 120 1 libnetwork.dylib 0x0000000120093255 nw_content_context_copy_protocol_metadata + 517 2 CFNetwork 0x00000001148d82a3 _CFHTTPServerResponseEnqueue + 32657 3 libdispatch.dylib 0x000000011ed2bf11 _dispatch_call_block_and_release + 12 4 libdispatch.dylib 0x000000011ed2ce8e _dispatch_client_callout + 8 5 libdispatch.dylib 0x000000011ed336fd _dispatch_lane_serial_drain + 788 6 libdispatch.dylib 0x000000011ed342c5 _dispatch_lane_invoke + 476 7 libdispatch.dylib 0x000000011ed3fb65 _dispatch_workloop_worker_thread + 719 8 libsystem_pthread.dylib 0x00007fff52305499 _pthread_wqthread + 314 9 libsystem_pthread.dylib 0x00007fff52304467 start_wqthread + 15 2021-03-19 18:47:03.477224+0200 xxx[35545:639369] [websocket] Read completed with an error Operation canceled
This happens only on iOS 13.7 systems, apparently on iOS 14.4 I get only the last message:
Code Block [websocket] Read completed with an error Operation canceled
which seems to be legit.
I think the problem is that I close the socket during the socket listening ("receiveMessage") is active. But honestly I think that should not be a problem, because I expect to be able to close anytime a socket, even if I'm trying to read something from it.
My question would be, can I ignore this "simulated crash" or is it possible, that it will make some problems in different cases? Or is my approach good, to call the message receiving method continuously and to close simply the socket when it is needed? Anybody faced the same problem?