Skip to content

Live: Crash for invalid live stream state when unmount HTTP. v6.0.146 v7.0.3#4141

Merged
winlinvip merged 3 commits intoossrs:developfrom
retamia:bugfix/restart-publish-error
Aug 15, 2024
Merged

Live: Crash for invalid live stream state when unmount HTTP. v6.0.146 v7.0.3#4141
winlinvip merged 3 commits intoossrs:developfrom
retamia:bugfix/restart-publish-error

Conversation

@retamia
Copy link
Copy Markdown
Contributor

@retamia retamia commented Aug 12, 2024

When unpublishing, the handler callback that will stop the coroutine:

_can_publish = true;
handler->on_unpublish(req);

In this handler, the http_unmount will be called:

void SrsHttpStreamServer::http_unmount(SrsRequest* r)
    cache->stop();

In this http_unmount function, there could be context switching. In such a situation, a new connection might publish the stream while the unpublish process is freeing the stream, leading to a crash.

To prevent a new publisher, we should change the state only after all handlers and hooks are completed.

…e are active viewers, it can cause an abnormal state.

ossrs#4140
@winlinvip winlinvip changed the title fix: when the stream source stops and immediately restarts, it can cause an abnormal state. Live: Crash for invalid live stream state when unpublishing Aug 14, 2024
@winlinvip winlinvip changed the title Live: Crash for invalid live stream state when unpublishing Live: Crash for invalid live stream state when unmount HTTP Aug 14, 2024
@winlinvip winlinvip changed the title Live: Crash for invalid live stream state when unmount HTTP Live: Crash for invalid live stream state when unmount HTTP. v6.0.146 v7.0.3 Aug 14, 2024
@winlinvip winlinvip added the RefinedByAI Refined by AI/GPT. label Aug 14, 2024
@winlinvip winlinvip merged commit 38417d9 into ossrs:develop Aug 15, 2024
winlinvip added a commit that referenced this pull request Aug 15, 2024
…#4141)

When unpublishing, the handler callback that will stop the coroutine:

```cpp
_can_publish = true;
handler->on_unpublish(req);
```

In this handler, the `http_unmount` will be called:

```cpp
void SrsHttpStreamServer::http_unmount(SrsRequest* r)
    cache->stop();
```

In this `http_unmount` function, there could be context switching. In
such a situation, a new connection might publish the stream while the
unpublish process is freeing the stream, leading to a crash.

To prevent a new publisher, we should change the state only after all
handlers and hooks are completed.

---------

Co-authored-by: liumengte <liumengte@visionular.com>
Co-authored-by: winlin <winlinvip@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RefinedByAI Refined by AI/GPT.

Development

Successfully merging this pull request may close these issues.

requesting the HTTP-FLV using the HEAD method will cause a nullptr crash

2 participants