Pjsip Crashed on RegState callback

三世轮回 提交于 2019-12-18 07:24:13

问题


In my class that extends SipAccount class I've onRegState() callback which i receive frequently I've notice that after few callback later at any callback like 4th or 5th time it crashes.

this is the code from onRegState() callback

 @Override
    public void onRegState(OnRegStateParam prm)
    {
        Log.d(TAG, "onRegState...");
        PresenceStatus prsenStatus =  new PresenceStatus();

        if (prm.getCode().swigValue()/100 == 2)
        {
            Log.d(TAG, "Going online!");
            listener.onLogIn(true);
            prsenStatus.setStatus(pjsua_buddy_status.PJSUA_BUDDY_STATUS_ONLINE);
        }
        else
        {
            Log.d(TAG, "Going offline!");
            listener.onLogIn(false);
            prsenStatus.setStatus(pjsua_buddy_status.PJSUA_BUDDY_STATUS_OFFLINE);
        }

        try
        {

            sipAccount.setOnlineStatus(prsenStatus);

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

This is the log from pjsip client.

06-21 12:37:16.172 10428-10645/com.safarifone.waafi A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 10645 (Thread-3816)
    06-21 12:37:16.279 184-184/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    06-21 12:37:16.279 184-184/? I/DEBUG: Build fingerprint: 'google/occam/mako:5.1.1/LMY48T/2237560:user/release-keys'
    06-21 12:37:16.279 184-184/? I/DEBUG: Revision: '11'
    06-21 12:37:16.279 184-184/? I/DEBUG: ABI: 'arm'
    06-21 12:37:16.279 184-184/? I/DEBUG: pid: 10428, tid: 10645, name: Thread-3816  >>> com.safarifone.waafi <<<
    06-21 12:37:16.279 184-184/? I/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
    06-21 12:37:16.374 184-184/? I/DEBUG:     r0 00000000  r1 00002995  r2 00000006  r3 00000000
    06-21 12:37:16.374 184-184/? I/DEBUG:     r4 a2950dd8  r5 00000006  r6 0000000b  r7 0000010c
    06-21 12:37:16.374 184-184/? I/DEBUG:     r8 b89629b8  r9 b89629b8  sl b6e66155  fp a29502a4
    06-21 12:37:16.374 184-184/? I/DEBUG:     ip 00002995  sp a2950238  lr b6e66989  pc b6e8be24  cpsr 600f0010
    06-21 12:37:16.375 184-184/? I/DEBUG: backtrace:
    06-21 12:37:16.375 184-184/? I/DEBUG:     #00 pc 0003be24  /system/lib/libc.so (tgkill+12)
    06-21 12:37:16.375 184-184/? I/DEBUG:     #01 pc 00016985  /system/lib/libc.so (pthread_kill+52)
    06-21 12:37:16.375 184-184/? I/DEBUG:     #02 pc 00017597  /system/lib/libc.so (raise+10)
    06-21 12:37:16.375 184-184/? I/DEBUG:     #03 pc 00013d3d  /system/lib/libc.so (__libc_android_abort+36)
    06-21 12:37:16.375 184-184/? I/DEBUG:     #04 pc 000124ec  /system/lib/libc.so (abort+4)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #05 pc 00464d10  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (__gnu_cxx::__verbose_terminate_handler()+348)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #06 pc 0045e9e4  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (__cxxabiv1::__terminate(void (*)())+8)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #07 pc 0045ea84  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (std::terminate()+12)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #08 pc 0045ec10  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (__cxa_throw+156)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #09 pc 000d6c00  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (SwigDirector_Account::onRegState(pj::OnRegStateParam&)+400)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #10 pc 0015ef9c  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pj::Endpoint::on_reg_state2(int, pjsua_reg_info*)+268)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #11 pc 001996c0  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (regc_cb+1424)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #12 pc 001dc944  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (call_callback+124)
    06-21 12:37:16.376 184-184/? I/DEBUG:     #13 pc 001ddc28  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (regc_tsx_callback+2120)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #14 pc 00225a18  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (mod_util_on_tsx_state+232)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #15 pc 00221304  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (tsx_set_state+540)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #16 pc 00224dfc  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (tsx_on_state_proceeding_uac+712)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #17 pc 002240cc  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (tsx_on_state_calling+656)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #18 pc 002227a0  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pjsip_tsx_recv_msg+180)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #19 pc 002206ac  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (mod_tsx_layer_on_rx_response+232)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #20 pc 002052b4  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pjsip_endpt_process_rx_data+696)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #21 pc 002055d0  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (endpt_on_rx_msg+636)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #22 pc 0020f6b4  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pjsip_tpmgr_receive_packet+1908)
    06-21 12:37:16.377 184-184/? I/DEBUG:     #23 pc 002152e8  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (on_data_read+252)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #24 pc 00351ce0  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (ioqueue_on_read_complete+208)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #25 pc 00347a14  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (ioqueue_dispatch_read_event+940)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #26 pc 0034a1a8  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pj_ioqueue_poll+1408)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #27 pc 00204e20  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pjsip_endpt_handle_events2+328)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #28 pc 001ae420  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (pjsua_handle_events+92)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #29 pc 001ab320  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (worker_thread+32)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #30 pc 0034b9c8  /data/app/com.safarifone.waafi-1/lib/arm/libpjsua2.so (thread_main+176)
    06-21 12:37:16.378 184-184/? I/DEBUG:     #31 pc 00016173  /system/lib/libc.so (__pthread_start(void*)+30)
    06-21 12:37:16.379 184-184/? I/DEBUG:     #32 pc 0001409b  /system/lib/libc.so (__start_thread+6)

回答1:


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:user85@192.168.0.1:5065;transport=tcp
09-07 19:27:49.523 25309-25328/? I/System.out: 19:27:49.523    pjsua_acc.c  .Account sip:user85@192.168.0.1: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:user85@192.168.0.102: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:user85@192.168.0.1>;tag=4qxB-NvGjIr6mYvHsTZodmy3jlZbSaId
09-07 19:27:49.527 25309-25328/? I/System.out: To: <sip:user85@192.168.0.1>
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:user85@192.168.0.102: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:     #04 pc 00017034  /system/lib/libc.so (abort+4)
09-07 19:27:50.064 25454-25454/? A/DEBUG:     #05 pc 001309af  /data/app/?-1/lib/arm/libpjsua2.so (_ZN9__gnu_cxx27__verbose_terminate_handlerEv+226)
09-07 19:27:50.064 25454-25454/? A/DEBUG:     #06 pc 0012b665  /data/app/?-1/lib/arm/libpjsua2.so (_ZN10__cxxabiv111__terminateEPFvvE+4)
09-07 19:27:50.064 25454-25454/? A/DEBUG:     #07 pc 0012b6d9  /data/app/?-1/lib/arm/libpjsua2.so (_ZSt9terminatev+8)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #08 pc 0012b7fd  /data/app/?-1/lib/arm/libpjsua2.so (__cxa_throw+120)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #09 pc 0006cfe3  /data/app/?-1/lib/arm/libpjsua2.so (_ZN20SwigDirector_Account10onRegStateERN2pj15OnRegStateParamE+186)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #10 pc 00091a53  /data/app/?-1/lib/arm/libpjsua2.so (_ZN2pj8Endpoint13on_reg_state2EiP14pjsua_reg_info+110)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #11 pc 000a8771  /data/app/?-1/lib/arm/libpjsua2.so (regc_cb+1092)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #12 pc 000c0c81  /data/app/?-1/lib/arm/libpjsua2.so (regc_tsx_callback+1368)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #13 pc 000d5223  /data/app/?-1/lib/arm/libpjsua2.so (tsx_set_state+190)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #14 pc 000d607b  /data/app/?-1/lib/arm/libpjsua2.so (send_msg_callback+446)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #15 pc 000cdb09  /data/app/?-1/lib/arm/libpjsua2.so (stateless_send_transport_cb+68)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #16 pc 000d0291  /data/app/?-1/lib/arm/libpjsua2.so (transport_send_callback+20)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #17 pc 000d21fb  /data/app/?-1/lib/arm/libpjsua2.so (on_data_sent+38)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #18 pc 000d24fb  /data/app/?-1/lib/arm/libpjsua2.so (on_connect_complete+82)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #19 pc 00122e3d  /data/app/?-1/lib/arm/libpjsua2.so (ioqueue_dispatch_write_event+124)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #20 pc 00123c03  /data/app/?-1/lib/arm/libpjsua2.so (pj_ioqueue_poll+462)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #21 pc 000cd519  /data/app/?-1/lib/arm/libpjsua2.so (pjsip_endpt_handle_events2+90)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #22 pc 000ae505  /data/app/?-1/lib/arm/libpjsua2.so (pjsua_handle_events+32)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #23 pc 000ae529  /data/app/?-1/lib/arm/libpjsua2.so (worker_thread+16)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #24 pc 0012453d  /data/app/?-1/lib/arm/libpjsua2.so (thread_main+40)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #25 pc 000470b3  /system/lib/libc.so (_ZL15__pthread_startPv+22)
09-07 19:27:50.065 25454-25454/? A/DEBUG:     #26 pc 00019e3d  /system/lib/libc.so (__start_thread+6)

As you see, the library crashed immediately after receiving "Connection refused" error and planing the next retry (according to logs). So we made a test to prove the suggestion - we configured the SIP server to refuse any connections, and we got it! So the problem appeared when there is a connection error.

Keeping this in mind I placed a break point in the onRegState() callback. I tried again and got the break point hit, then I released it and app crashed. Then I commented out my code in the method, and tried again: break point hit, release and... NO CRASH It was strange, because my logic on that was pretty light and doing nothing with Pjsip itself.

Then I put a log to find out which thread the callback is running and... surprise!

The answer (TL;DR) (mb reason is incorrect)

The onRegState() callback method runs in one of the Pjsip threads created by it somewhere internally. So once I replaced the call to my code here by posting it to my worker thread crashes disappeared. Looks like Pjsip is waiting for all it's callback method to return early and doesn't imply them to delay for any amount of time.

So I suggest to wrap calls to your code from there with Runnable and post it to a Handler (no matter to UI thread or to your own worker thread) and crashes will be gone. I haven't tested other Pjsip callbacks threads - are they also internal Pjsip threads or not? But I'm pretty sure they are and plan to wrap all calls to my code from any Pjsip callback the same way (Runnable -> post to Hadler)

So your code may looks like this to overcome the problem:

@Override
public void onRegState(OnRegStateParam prm) {
    Log.d(TAG, "onRegState...");

    final int stateCode = prm.getCode().swigValue();

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            PresenceStatus prsenStatus =  new PresenceStatus();

            if (stateCode /100 == 2) {
                Log.d(TAG, "Going online!");
                listener.onLogIn(true);
                prsenStatus.setStatus(pjsua_buddy_status.PJSUA_BUDDY_STATUS_ONLINE);
            } else {
                Log.d(TAG, "Going offline!");
                listener.onLogIn(false);
                prsenStatus.setStatus(pjsua_buddy_status.PJSUA_BUDDY_STATUS_OFFLINE);
            }

            try {
                sipAccount.setOnlineStatus(prsenStatus);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

where mHandler is your Handler of the thread you use to work with Pjsip created somewhere. Or you may use any other solution that offloads this method from any work to your thread...

Update

  1. I have checked and found that all Pjsip callbacks run in threads cretead by library. Except the first call to the onCallState(OnCallStateParam prm) of the Call. First time it is called in the same thread where the Call was created, but next calls happen on different threads created by the Pjsip, each time a new thread.
  2. I have found that previously I threw a new RuntimeException for registration failure. So actually this crash is a result of unexpected Exception in your code executed by this callback.

So Exception in the Pjsip thread leads to the native library crash.

Updated answer

I conclude that the library crashes when there was an unexpected Exception in the code executed by the callback (in the callback thread).

But I recommend the same solution:

Don't run any business-logic in the callback, post it to your Thread

Thus you will both:

  1. Protect from race conditions between library callback treads and your logic thread (UI, worker or whatever)
  2. And protect from this kind of mystery crashes in the library, getting good old java exceptions =)


来源:https://stackoverflow.com/questions/44676012/pjsip-crashed-on-regstate-callback

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!