srs: Fix the issue of srs randomly failing to start during machine startup.#2012
srs: Fix the issue of srs randomly failing to start during machine startup.#2012PieerePi wants to merge 3 commits intoossrs:developfrom
Conversation
感觉好像是son进程还在SrsDtlsCertificate::initialize过程中就直接退出了; 让father进程等一下再退出就好了; 手工启动srs好像没有此问题。
Codecov Report
@@ Coverage Diff @@
## develop #2012 +/- ##
========================================
Coverage 57.17% 57.17%
========================================
Files 125 125
Lines 52707 52707
========================================
+ Hits 30134 30135 +1
+ Misses 22573 22572 -1
Continue to review full report at Codecov.
|
trunk/src/main/srs_main_server.cpp
Outdated
| } | ||
|
|
||
| if(pid > 0) { | ||
| sleep(3); |
There was a problem hiding this comment.
Why do we have to wait for 3 seconds? Can you provide some information?
TRANS_BY_GPT3
There was a problem hiding this comment.
OpenSSL has some issues with shared processes between parent and child. Some references are provided for your reference.
https://wiki.openssl.org/index.php/Random_fork-safety
https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_fork_child.html (These new methods are available after 1.1.1, but currently srs is using 1.1.0e.)
In this case, I am asking the parent process to wait for a while, allowing the child process to successfully complete _srs_rtc_dtls_certificate->initialize before the parent process exits. Otherwise, there is a high probability of _srs_rtc_dtls_certificate->initialize failing, and srs cannot start with the machine.
Waiting for 3 seconds in the parent process is just a workaround and there may be better methods available. For example, the approach used by Janus is to have the parent process wait until the child process has finished initializing before exiting.
janus.c:4124, /* Ok, we're the parent: let's wait for the child to tell us everything started fine */
Is this problem only present when there is WebRTC functionality?
TRANS_BY_GPT3
There was a problem hiding this comment.
This solution also solves the problem of initializing openssl, using sleep is definitely a temporary solution. Let me see how to solve it completely.
TRANS_BY_GPT3
There was a problem hiding this comment.
Tested, not working!
TRANS_BY_GPT3
There was a problem hiding this comment.
Tested, not working!
Oh, it's possible that we're not dealing with the same issue. Please try another method.
TRANS_BY_GPT3
|
https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_fork_child.html
It seems that Linux has no problem.
|
|
Although this PR is not being merged, thank you very much @PieerePi.
|
srs: Fix the issue of srs randomly failing to start during machine startup.
TRANS_BY_GPT3