[rtmpdump] librtmp thread-safeness question

Andrey Turkin andrey.turkin at gmail.com
Tue Dec 16 12:46:54 CET 2014


Hi all,

I've run into an issue with streaming to RTMP server (via libav) in
multithreaded application - it would sometimes crash at start.

Debugging revealed following (reduced) callstack:

openssl!lh_insert
openssl!int_err_set_item
...
openssl!SSL_load_error_strings
librtmp!RTMP_TLS_Init
librtmp!RTMP_Init
libavformat!rtmp_open
...
libavformat!avio_open2
my application

After reading openssl/librtmp/libav code it seems to me that there is
not one but two different race conditions. Firstly, there is an
obvious race in RTMP_Init before and during the call to RTMP_TLS_Init.

Secondly, although openssl is supposed to be threadsafe, it is only
true if its threading support is initialized via CRYPTO_thread_setup
or alternative code which does something similar.

I don't know if that is a bug in librtmp or incorrect usage by libav
or something else.

So, my question is whether librtmp is supposed to be thread-safe to a
some degree; and if it is then which API calls are supposed to be
thread-safe and which are not. I saw a message in this list which said
calling librtmp functions with same session handle from different
threads is not safe (which makes sense) but I cannot find any
information about what usage should be safe.

>From what I can see (with regard to not initialized openssl threading)
it looks like librtmp is not thread-safe as a whole and all calls to
it must be serialized.

Regards,

  Andrey Turkin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mplayerhq.hu/pipermail/rtmpdump/attachments/20141216/6bfe88cf/attachment.html>


More information about the rtmpdump mailing list