Preface
I was also struggling on this problem for several months and got the same on the real-world app usage (crashes form the play market). And used your code to handle registration results.
The difficult was that we couldn't experience that issues during our tests on any of our devices but our users got it approx 500 crashes per 1000 installs (very high).
Initially I was dealing with Pjsip from UI thread, then I tried to create my own thread for the Pjsip (with uaConfig.setThreadCnt(0) and uaConfig.setMainThreadOnly(true)) but it failed to work at all, or I don't know how to do this right and there is no clue about it anywhere. Then I moved all our business logic from UI to worker thread and worked with Pjsip from worker thread. Nothing helped and the issues were the same.
Finally yesterday we were able to catch this issue and at the same time we had Pjsip logs turned on level 9.
And here is the full log for this crash with preceding info (I've replaced actual server credentials for obvious reason):
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.474 sip_endpoint.c .Module "mod-pjsua-log" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 sip_endpoint.c .Module "mod-tsx-layer" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 sip_endpoint.c .Module "mod-stateful-util" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 sip_endpoint.c .Module "mod-ua" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 sip_endpoint.c .Module "mod-100rel" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 sip_endpoint.c .Module "mod-pjsua" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 sip_endpoint.c .Module "mod-invite" registered
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 android_jni_de ..Android JNI sound library initialized
09-07 19:27:49.475 25309-25328/? I/System.out: 19:27:49.475 pjlib ..select() I/O Queue created (0xd1f53214)
09-07 19:27:49.476 25309-25328/? I/System.out: 19:27:49.476 conference.c ..Creating conference bridge with 12 ports
09-07 19:27:49.476 25309-25328/? I/System.out: 19:27:49.476 Master/sound ..Using delay buffer with WSOLA.
09-07 19:27:49.477 25309-25328/? I/System.out: 19:27:49.477 pjsua_vid.c ..Initializing video subsystem..
09-07 19:27:49.478 25309-25328/? I/System.out: 19:27:49.477 openh264.cpp ...OpenH264 codec initialized
09-07 19:27:49.478 25309-25328/? I/System.out: 19:27:49.478 opengl_dev.c ...OpenGL device initialized
09-07 19:27:49.489 25309-25328/? I/System.out: 19:27:49.489 android_dev.c ...Android video capture initialized with 0 device(s):
09-07 19:27:49.489 25309-25328/? I/System.out: 19:27:49.489 colorbar_dev.c ...Colorbar video src initialized with 2 device(s):
09-07 19:27:49.489 25309-25328/? I/System.out: 19:27:49.489 colorbar_dev.c ... 0: Colorbar generator
09-07 19:27:49.489 25309-25328/? I/System.out: 19:27:49.489 colorbar_dev.c ... 1: Colorbar-active
09-07 19:27:49.489 25309-25328/? I/System.out: 19:27:49.489 sip_endpoint.c .Module "mod-evsub" registered
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 sip_endpoint.c .Module "mod-presence" registered
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 evsub.c .Event pkg "presence" registered by mod-presence
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 sip_endpoint.c .Module "mod-mwi" registered
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 evsub.c .Event pkg "message-summary" registered by mod-mwi
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 sip_endpoint.c .Module "mod-refer" registered
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 evsub.c .Event pkg "refer" registered by mod-refer
09-07 19:27:49.490 25309-25328/? I/System.out: 19:27:49.490 sip_endpoint.c .Module "mod-pjsua-pres" registered
09-07 19:27:49.491 25309-25328/? I/System.out: 19:27:49.491 sip_endpoint.c .Module "mod-pjsua-im" registered
09-07 19:27:49.492 25309-25328/? I/System.out: 19:27:49.491 sip_endpoint.c .Module "mod-pjsua-options" registered
09-07 19:27:49.492 25309-25328/? I/System.out: 19:27:49.492 pjsua_core.c .1 SIP worker threads created
09-07 19:27:49.492 25309-25328/? I/System.out: 19:27:49.492 pjsua_core.c .pjsua version 2.6-svn for Linux-3.10.73/armv8l initialized
09-07 19:27:49.492 25309-25328/? I/System.out: 19:27:49.492 pjsua_core.c .PJSUA state changed: CREATED --> INIT
09-07 19:27:49.496 25309-25328/? I/System.out: 19:27:49.496 pjsua_core.c SIP UDP socket reachable at 192.168.0.102:49790
09-07 19:27:49.496 25309-25328/? I/System.out: 19:27:49.496 udp0xc5e8bc00 SIP UDP transport started, published address is 192.168.0.102:49790
09-07 19:27:49.499 25309-25328/? I/System.out: 19:27:49.499 tcptp:39629 SIP TCP listener ready for incoming connections at 192.168.0.102:39629
09-07 19:27:49.499 25309-25328/? I/System.out: 19:27:49.499 pjsua_core.c PJSUA state changed: INIT --> STARTING
09-07 19:27:49.499 25309-25328/? I/System.out: 19:27:49.499 sip_endpoint.c .Module "mod-unsolicited-mwi" registered
09-07 19:27:49.499 25309-25328/? I/System.out: 19:27:49.499 pjsua_core.c .PJSUA state changed: STARTING --> RUNNING
09-07 19:27:49.523 25309-25328/? I/System.out: 19:27:49.523 pjsua_acc.c Adding account: id=sip:[email protected]:5065;transport=tcp
09-07 19:27:49.523 25309-25328/? I/System.out: 19:27:49.523 pjsua_acc.c .Account sip:[email protected]:5065;transport=tcp added with id 0
09-07 19:27:49.523 25309-25328/? I/System.out: 19:27:49.523 pjsua_acc.c .Acc 0: setting registration..
09-07 19:27:49.524 25309-25328/? I/System.out: 19:27:49.524 tcpc0xc8004414 ..TCP client transport created
09-07 19:27:49.525 25309-25328/? I/System.out: 19:27:49.525 tcpc0xc8004414 ..TCP transport 192.168.0.102:43292 is connecting to 192.168.0.1:5065...
09-07 19:27:49.525 25309-25328/? I/System.out: 19:27:49.525 pjsua_acc.c ..Contact for acc 0 updated: <sip:[email protected]:43292;transport=TCP;ob>;reg-id=1;+sip.instance="<urn:uuid:00000000-0000-0000-0000-0000e922f243>"
09-07 19:27:49.526 25309-25328/? I/System.out: 19:27:49.526 endpoint ..Request msg REGISTER/cseq=27093 (tdta0xf2abe064) created.
09-07 19:27:49.526 25309-25328/? I/System.out: 19:27:49.526 tsx0xc5189864 ...Transaction created for Request msg REGISTER/cseq=27094 (tdta0xf2abe064)
09-07 19:27:49.526 25309-25328/? I/System.out: 19:27:49.526 tsx0xc5189864 ..Sending Request msg REGISTER/cseq=27094 (tdta0xf2abe064) in state Null
09-07 19:27:49.527 25309-25328/? I/System.out: 19:27:49.526 sip_resolve.c ...Target '192.168.0.1:5065' type=TCP resolved to '192.168.0.1:5065' type=TCP (TCP transport)
09-07 19:27:49.527 25309-25328/? I/System.out: 19:27:49.527 pjsua_core.c ...TX 670 bytes Request msg REGISTER/cseq=27094 (tdta0xf2abe064) to TCP 192.168.0.1:5065:
09-07 19:27:49.527 25309-25328/? I/System.out: REGISTER sip:192.168.0.1:5065;transport=tcp SIP/2.0
09-07 19:27:49.527 25309-25328/? I/System.out: Via: SIP/2.0/TCP 192.168.0.102:43292;rport;branch=z9hG4bKPjF2B-OwmauIYhdNKR-ZgJx.-1MSDez4W6;alias
09-07 19:27:49.527 25309-25328/? I/System.out: Max-Forwards: 70
09-07 19:27:49.527 25309-25328/? I/System.out: From: <sip:[email protected]>;tag=4qxB-NvGjIr6mYvHsTZodmy3jlZbSaId
09-07 19:27:49.527 25309-25328/? I/System.out: To: <sip:[email protected]>
09-07 19:27:49.527 25309-25328/? I/System.out: Call-ID: C5IqW1iZ3iPJDNHNPtQnk0L-9IoX3iUs
09-07 19:27:49.527 25309-25328/? I/System.out: CSeq: 27094 REGISTER
09-07 19:27:49.527 25309-25328/? I/System.out: User-Agent: Pjsua2 Android 2.6-svn
09-07 19:27:49.527 25309-25328/? I/System.out: Supported: outbound, path
09-07 19:27:49.527 25309-25328/? I/System.out: Contact: <sip:[email protected]:43292;transport=TCP;ob>;reg-id=1;+sip.instance="<urn:uuid:00000000-0000-0000-0000-0000e922f243>"
09-07 19:27:49.527 25309-25328/? I/System.out: Expires: 300
09-07 19:27:49.527 25309-25328/? I/System.out: Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
09-07 19:27:49.527 25309-25328/? I/System.out: Content-Length: 0
09-07 19:27:49.527 25309-25328/? I/System.out: --end msg--
09-07 19:27:49.527 25309-25328/? I/System.out: 19:27:49.527 tsx0xc5189864 ...State changed from Null to Calling, event=TX_MSG
09-07 19:27:49.527 25309-25328/? I/System.out: 19:27:49.527 pjsua_acc.c ..Acc 0: Registration sent
09-07 19:27:49.629 25309-25449/? I/System.out: 19:27:49.628 tcpc0xc8004414 !TCP connect() error: Connection refused [code=120111]
09-07 19:27:49.631 25309-25449/? I/System.out: 19:27:49.629 tsx0xc5189864 Failed to send Request msg REGISTER/cseq=27094 (tdta0xf2abe064)! err=120111 (Connection refused)
09-07 19:27:49.632 25309-25449/? I/System.out: 19:27:49.631 tsx0xc5189864 State changed from Calling to Terminated, event=TRANSPORT_ERROR
09-07 19:27:49.634 25309-25449/? I/System.out: 19:27:49.633 pjsua_acc.c ..SIP registration failed, status=503 (Connection refused)
09-07 19:27:49.635 25309-25449/? I/System.out: 19:27:49.634 pjsua_acc.c ..Scheduling re-registration retry for acc 0 in 7 seconds..
09-07 19:27:49.900 25453-25449/? A/google-breakpad: Microdump skipped (uninteresting)
09-07 19:27:49.930 25309-25449/? W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
09-07 19:27:49.930 25309-25449/? W/google-breakpad: Chrome build fingerprint:
09-07 19:27:49.930 25309-25449/? W/google-breakpad: 10
09-07 19:27:49.930 25309-25449/? W/google-breakpad: 10
09-07 19:27:49.930 25309-25449/? W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
09-07 19:27:49.933 25309-25449/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 25449 (Thread-18)
[ 09-07 19:27:49.940 16075:16075 W/ ]
debuggerd: handling request: pid=25309 uid=11700 gid=11700 tid=25449
09-07 19:27:49.970 25454-25454/? W/debuggerd: type=1400 audit(0.0:1124): avc: denied { search } for name="?" dev="dm-2" ino=441666 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0
09-07 19:27:50.050 25454-25454/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
09-07 19:27:50.051 25454-25454/? A/DEBUG: Build fingerprint: 'google/bullhead/bullhead:7.1.2/N2G48C/4104010:user/release-keys'
09-07 19:27:50.051 25454-25454/? A/DEBUG: Revision: 'rev_1.0'
09-07 19:27:50.051 25454-25454/? A/DEBUG: ABI: 'arm'
09-07 19:27:50.051 25454-25454/? A/DEBUG: pid: 25309, tid: 25449, name: Thread-18 >>> ? <<<
09-07 19:27:50.051 25454-25454/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
09-07 19:27:50.051 25454-25454/? A/DEBUG: r0 00000000 r1 00006369 r2 00000006 r3 00000008
09-07 19:27:50.051 25454-25454/? A/DEBUG: r4 c3c01978 r5 00000006 r6 c3c01920 r7 0000010c
09-07 19:27:50.051 25454-25454/? A/DEBUG: r8 c545f7e0 r9 c4022858 sl c3ff8a50 fp ffffffff
09-07 19:27:50.051 25454-25454/? A/DEBUG: ip 00000000 sp c3c01048 lr f47e45e7 pc f47e6e44 cpsr 200f0010
09-07 19:27:50.063 25454-25454/? A/DEBUG: backtrace:
09-07 19:27:50.064 25454-25454/? A/DEBUG: #00 pc 00049e44 /system/lib/libc.so (tgkill+12)
09-07 19:27:50.064 25454-25454/? A/DEBUG: #01 pc 000475e3 /system/lib/libc.so (pthread_kill+34)
09-07 19:27:50.064 25454-25454/? A/DEBUG: #02 pc 0001d8a5 /system/lib/libc.so (raise+10)
09-07 19:27:50.064 25454-25454/? A/DEBUG: #03 pc 000193f1 /system/lib/libc.so (__libc_android_abort+34)
09-07 19:27:50.064 25454-25454/? A/DEBUG:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…