curl-library
Re: Problem sharing one instance of openssl between curl and pjsip
Date: Wed, 20 Apr 2016 01:34:18 -0400
On 4/19/2016 10:00 AM, JOHAN LANTZ wrote:
> Hi
>
> I have a .so for Android that encapsulates both pjsip and curl. In
> turn, both of them depend on openssl so all of them exist as static
> libs inside the final .so.
>
> The problem is that the sharing of openssl breaks something and I am
> not yet able to figure out what.
>
> Basically I do something like:
>
> * Start the pjsip stack, a ssl handshake is performed without any
> problems and we now have a working TLS socket with the sip server.
> * Do any http activity with curl
> * Break the sip connection, for instance by changing from wifi to
> 3g. This forces pjsip to try and re-register to the server using a
> new TLS connection.
>
> The problem is that after curl has been initialised, pjsip is never
> able to establish a new socket, ever again. The failure is very brief:
> !TLS connect() error: Unknown error 494241 [code=494241]
>
> I have tried to figure out what error 494241 means without success.
>
> My current assumption is that the error comes from inside openssl and
> that by initiating libcurl something shared is destroyed for pjsip.
> Curl keeps working fine but pjsip is never able to recover, not even
> after restarting the whole stack (including shutting down curl, which
> is strange).
>
> If I instead of having pjsip and curl reside in the same .so, split
> them into two .so files each with their own libssl.a and libcrypto.a
> it works fine. So the problem appears to be them sharing a context of
> some kind.
>
> I am not sure if its actually related but OkHttp seems to have had a
> similar issue at some point:
> https://github.com/square/okhttp/issues/184
> It might be completely unrelated (fortunately my app does not crash at
> least) but I wanted to mention it.
>
> So, I do have a solution in the dual .so approach but this increases
> quite a lot the .apk size of the Android app so I would be really
> interested in if someone can help me explain the root cause of the
> issue. It is easy to reproduce so I am happy to provide more info.
>
I don't know what that error is. Still based on what you describe I'm
fairly confident this is an OpenSSL problem, see [1] for an example. It
looks like you'll get some relief in the upcoming OpenSSL 1.1.0 [2][3]
(note: 'master' manpages are for 1.1.0). Until then if your other
library is handling its own locking callbacks and initialization for
OpenSSL then you can try initializing libcurl [4] without initializing
OpenSSL:
/* Initialize libcurl but don't have it init OpenSSL since pjsip init
will handle that */
curl_global_init(CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL);
[1]: https://reviewboard.asterisk.org/r/1006/
[2]: https://www.openssl.org/docs/manmaster/ssl/OPENSSL_init_ssl.html
[3]: https://www.openssl.org/docs/manmaster/crypto/threads.html
[4]: https://curl.haxx.se/libcurl/c/curl_global_init.html
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-04-20