Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1300 Problem of fd leakage when pulling non-existent http-flv stream #1304

Closed
wants to merge 1 commit into from

Conversation

rageJune
Copy link

@rageJune rageJune commented Jan 22, 2019

#1300 Small modification based on #636


TRANS_BY_GPT3

@@ -596,6 +597,7 @@ srs_error_t SrsHttpRecvThread::cycle()
SrsAutoFree(ISrsHttpMessage, req);

if ((err = conn->pop_message(&req)) != srs_success) {
trd_err = err;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The err here is shared by trd_err and wrapped err, we should free the trd_err then copy err to it.

winlinvip added a commit that referenced this pull request Apr 6, 2019
@winlinvip
Copy link
Member

winlinvip commented Apr 6, 2019

First, I will set the hstrs of SRS2 to on by default. As a streaming media server, it should actively fetch content from the origin. Reference: a8781ae

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Apr 6, 2019

Analyze the code and find that it is a low-level coroutine object. After actively exiting, the pull function cannot obtain the error.

The upper-level code will start a thread to read messages from the client.

srs_error_t SrsHttpRecvThread::cycle()
{
    srs_error_t err = srs_success;
    
    while ((err = trd->pull()) == srs_success) {
        ISrsHttpMessage* req = NULL;
        SrsAutoFree(ISrsHttpMessage, req);
        
        if ((err = conn->pop_message(&req)) != srs_success) {
            return srs_error_wrap(err, "pop message");

The pop_message function will return an error after the client closes the connection, and then it will be retrieved and returned by the pfn function.

void* SrsSTCoroutine::pfn(void* arg)
{
    SrsSTCoroutine* p = (SrsSTCoroutine*)arg;
    void* res = (void*)p->cycle();
    return res;

And this error code is stored in the return value of the st coroutine.

326	  /* Run thread main */
327	  thread->retval = (*thread->start)(thread->arg);
(gdb) p thread->retval
$1 = (void *) 0x9c87c0

Usually, when the stop function stops the thread, the return value of the coroutine is obtained so that pull can know if there is an error.

void SrsSTCoroutine::stop()
{
    if (!started || disposed) {
        return;
    }
    disposed = true;
    
    interrupt();
    
    void* res = NULL;
    int r0 = st_thread_join((st_thread_t)trd, &res);
    srs_assert(!r0);
    
    // Always override the error by the error from worker.
    if ((srs_error_t)res != srs_success) {
        srs_freep(trd_err);
        trd_err = (srs_error_t)res;

In fact, there is no place to call stop, so pull cannot obtain the error. The solution is to set trd_err when the coroutine naturally exits, so that pull can return the error.

TRANS_BY_GPT3

winlinvip added a commit that referenced this pull request Apr 6, 2019
@winlinvip
Copy link
Member

winlinvip commented Apr 6, 2019

SRS2, SRS3, Origin, and Edge modes all passed the test without any FD leakage issues.

Fixed.

TRANS_BY_GPT3

@winlinvip winlinvip closed this Apr 6, 2019
@winlinvip winlinvip changed the title #1300 拉取不存在的http-flv流时fd泄漏的问题 #1300 Problem of fd leakage when pulling non-existent http-flv stream Jul 29, 2023
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants