PJSIP: crash on pj_sockaddr_get_port when moving an iOS application in the background and then in the foreground

I have an iOS VOIP application using PJSIP v2.3.0.

After the release of iOS 11, I saw many examples of crashes below. I have a crashlytics integrated with my application and this is the flip side of the thread that crashed.

Crashed: Thread
0  libsystem_kernel.dylib         0x186819348 __pthread_kill + 8
1  libsystem_pthread.dylib        0x18692d354 pthread_kill$VARIANT$mp + 396
2  libsystem_c.dylib              0x186788fd8 abort + 140
3  libsystem_c.dylib              0x18675cabc basename_r + 314
4  MyApp                          0x101a2ab58 pj_sockaddr_get_port + 10115892
5  MyApp                          0x101a24e28 udp_on_read_complete + 10092036
6  MyApp                          0x1019bba74 ioqueue_dispatch_read_event + 9661008
7  MyApp                          0x1019bd1f0 pj_ioqueue_poll + 9667020
8  MyApp                          0x101a08788 pjsip_endpt_handle_events2 + 9975652
9  MyApp                          0x1019df334 worker_thread + 9806608
10 MyApp                          0x1019cf274 thread_main + 9740880
11 libsystem_pthread.dylib        0x18692c32c _pthread_body + 308
12 libsystem_pthread.dylib        0x18692c1f8 _pthread_body + 310
13 libsystem_pthread.dylib        0x18692ac38 thread_start + 4

Stream crash due to pj_sockaddr_get_port approval

PJ_ASSERT_RETURN(a->addr.sa_family == PJ_AF_INET ||
             a->addr.sa_family == PJ_AF_INET6, (pj_uint16_t)0xFFFF);

Note: PJ_ENABLE_EXTRA_CHECK is defined for my application 0, so PJ_ASSERT_RETURN is just PJ_ASSERT here.

The PJSIP logs leading to this crash are telling something interesting. The application is conceived, and it cancels the registration. When the application is brought to the forefront in a few minutes, it tries to register.

, crashlytics , , .

2017-09-28 21:00:11 TID=50691 [pjsua] Log Level-1 : 16:00:11.267     ioq_select  Error replacing socket: Invalid argument
2017-09-28 21:00:11 TID=50691 [pjsua] Log Level-1 : 16:00:11.267     udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120009] Bad file descriptor
2017-09-28 21:00:11 TID=50691 [pjsua] Log Level-1 : 16:00:11.267     udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120009] Bad file descriptor
.
.
.
2017-09-28 21:00:18 TID=50691 [pjsua] Log Level-1 : 16:00:15.256     udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120057] Socket is not connected
2017-09-28 21:00:18 TID=50691 [pjsua] Log Level-1 : 16:00:15.256     udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120057] Socket is not connected
2017-09-28 21:00:18 TID=50691 [pjsua] Log Level-1 : 16:00:15.256     udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120057] Socket is not connected
.
.
.
2017-09-28 21:00:18 TID=50691 [pjsua] Log Level-1 : 16:00:18.262 udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120038] Socket operation on non-socket
2017-09-28 21:00:18 TID=50691 [pjsua] Log Level-1 : 16:00:18.262 udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120038] Socket operation on non-socket
2017-09-28 21:00:18 TID=50691 [pjsua] Log Level-1 : 16:00:18.262 udp0x10de7f3a0  Warning: pj_ioqueue_recvfrom: [err 120038] Socket operation on non-socket

- udp_on_read_complete , . iOS , pjsip?

- ? / .

+4
1

, , , ioqueue_dispatch_read_event pjlib/src/pj/ioqueue_common_abs.c, replace_udp_sock(). , , on_read_complete .

, :

rc = replace_udp_sock(h);
if (rc != PJ_SUCCESS) {
  PJ_LOG(3, (THIS_FILE, "UDP socket replacement failed with error status %d", rc));
  if (has_lock) {
      pj_ioqueue_unlock_key(h);
  }
  return;
}

, .

+4

Source: https://habr.com/ru/post/1686777/


All Articles