app crash on network framework in iOS15.1

i use network.framewrok to create a tcp connection, but crashed on iOS15.1,here is some code:

- (void)connectToIP:(NSString *)ip
        onPort:(uint16_t)port
  completionHandler:(ConnectCallbackV2)callback
{
  if (@available(iOS 12.0, *)) {
     
    _callback = [callback copy];
 
    nw_parameters_configure_protocol_block_t tlsConfig = NW_PARAMETERS_DISABLE_PROTOCOL;
    nw_parameters_configure_protocol_block_t tcpConfig = ^(nw_protocol_options_t options) {
      NW_PARAMETERS_DEFAULT_CONFIGURATION(options);
      nw_tcp_options_set_connection_timeout(options, 5.0f);
      nw_tcp_options_set_enable_keepalive(options, true);
    };
    if (!_socket) {
      _socket = nw_connection_create(
                      nw_endpoint_create_host(ip.UTF8String, [NSString stringWithFormat:@"%d", port].UTF8String),
                      nw_parameters_create_secure_tcp(tlsConfig, tcpConfig));
    }
    nw_connection_set_queue(_socket, _delegateQueue);
    nw_connection_set_state_changed_handler(self->_socket, ^(nw_connection_state_t state, nw_error_t _Nullable error) {
      switch (state) {
        case nw_connection_state_failed:
        case nw_connection_state_cancelled: {
         // some logic
          break;
        }
        case nw_connection_state_ready: {
          // some logic
          break;
        }
        default: {
          // some logic
          break;
        }
      }
    });
     
    nw_connection_start(self->_socket);
  }
}

and crash as follow:

Thread 14 name:
Thread 14 Crashed:
0   libobjc.A.dylib               	0x000000019935f488 objc_retain + 8 (NSObject.mm:1775)
1   libnetwork.dylib              	0x0000000181a11620 nw_parameters_get_logging_disabled + 56 (parameters.m:7335)
2   libnetwork.dylib              	0x0000000181a0a52c __nw_connection_cancel_inner_block_invoke + 72 (connection.m:0)
3   libdispatch.dylib             	0x000000018096d914 _dispatch_call_block_and_release + 32 (init.c:1517)
4   libdispatch.dylib             	0x000000018096f660 _dispatch_client_callout + 20 (object.m:560)
5   libdispatch.dylib             	0x0000000180976de4 _dispatch_lane_serial_drain + 672 (inline_internal.h:2601)
6   libdispatch.dylib             	0x000000018097798c _dispatch_lane_invoke + 444 (queue.c:3937)
7   libdispatch.dylib             	0x0000000180978c74 _dispatch_workloop_invoke + 1796 (inline_internal.h:0)
8   libdispatch.dylib             	0x00000001809821a8 _dispatch_workloop_worker_thread + 656 (queue.c:6727)
9   libsystem_pthread.dylib       	0x00000001f18860f4 _pthread_wqthread + 288 (pthread.c:2541)
10  libsystem_pthread.dylib       	0x00000001f1885e94 start_wqthread + 8

the full crash log as file:

how can i fix this problem?

and crash as follow:

How reproducible is this? Are you only seeing this problem come in from the field? Or can you reproduce it in your office?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

 I can't reproducible this, but I found that the package downloaded from the app store crashed quite a lot.

I can't reproducible this, but I found that the package downloaded from the app store crashed quite a lot.

OK.

Consider the backtrace of the crashing thread:

Thread 14 name:
Thread 14 Crashed:
0   libobjc.A.dylib   … objc_retain + 8 …
1   libnetwork.dylib  … nw_parameters_get_logging_disabled + 56 …
2   libnetwork.dylib  … __nw_connection_cancel_inner_block_invoke + 72 …
3   libdispatch.dylib … _dispatch_call_block_and_release + 32 …

This suggest a memory management problem. My advice is that you use the standard memory debugging tools to see if they help make the problem more reproducible.

ps My best guess right now is that this is a problem in the OS, not in your code and I’m hoping that the above-mentioned tools help confirm this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

app crash on network framework in iOS15.1
 
 
Q