librtmp thread-safeness question
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
Hi, Le 16/12/2014 12:46, Andrey Turkin a écrit :
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.
Check this patch: https://lists.mplayerhq.hu/pipermail/rtmpdump/2014-September/002380.html
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
_______________________________________________ rtmpdump mailing list rtmpdump@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/rtmpdump
2014-12-17 11:25 GMT+03:00 Rafaël Carré <funman@videolan.org>:
Check this patch: https://lists.mplayerhq.hu/pipermail/rtmpdump/2014-September/002380.html
Thanks for the answer (though this patch cannot help me because I'm using Zeranoe builds of libav libraries and cannot patch anything). I found how to "trick" librtmp into initializing itself via libav API so this issue isn't pressing for me anymore. However this bug remains, with at least Zeranoe builds (and probably many others) affected and it should be fixed in tree. So my question remains. I hope someone maintaining librtmp is reading this list and can give some answer. Basically, either of "it is librtmp's bug and we won't fix it", "it is librtmp's bug and we are going to fix it", "it is not librtmp's bug because ffmpeg/libav is using it wrong in such and such ways" (in which case I'll go bug ffmpeg people) or "these API functions are not thread-safe and these are with following conditions" will do. Regards, Andrey Turkin
participants (2)
-
Andrey Turkin -
Rafaël Carré