1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/doc
Winlin 740f0d38ec
Edge: Fix flv edge crash when http unmount. v6.0.154 v7.0.13 (#4166)
Edge FLV is not working because it is stuck in an infinite loop waiting.
Previously, there was no need to wait for exit since resources were not
being cleaned up. Now, since resources need to be cleaned up, it must
wait for all active connections to exit, which causes this issue.

To reproduce the issue, start SRS edge, run the bellow command and press
`CTRL+C` to stop the request:

```bash
curl http://localhost:8080/live/livestream.flv -v >/dev/null
```

It will cause edge to fetch stream from origin, and free the consumer
when client quit. When `SrsLiveStream::do_serve_http` return, it will
free the consumer:

```cpp
srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) {
    SrsUniquePtr<SrsLiveConsumer> consumer(consumer_raw);
```

Keep in mind that in this moment, the stream is alive, because only set
to not alive after this function return:

```cpp
    alive_viewers_++;
    err = do_serve_http(w, r); // Free 'this' alive stream.
    alive_viewers_--; // Crash here, because 'this' is freed.
```

When freeing the consumer, it will cause the source to unpublish and
attempt to free the HTTP handler, which ultimately waits for the stream
not to be alive:

```cpp
SrsLiveConsumer::~SrsLiveConsumer() {
    source_->on_consumer_destroy(this);

void SrsLiveSource::on_consumer_destroy(SrsLiveConsumer* consumer) {
    if (consumers.empty()) {
        play_edge->on_all_client_stop();

void SrsLiveSource::on_unpublish() {
    handler->on_unpublish(req);

void SrsHttpStreamServer::http_unmount(SrsRequest* r) {
    if (stream->entry) stream->entry->enabled = false;

    for (; i < 1024; i++) {
        if (!cache->alive() && !stream->alive()) {
            break;
        }
        srs_usleep(100 * SRS_UTIME_MILLISECONDS);
    }
```

After 120 seconds, it will free the stream and cause SRS to crash
because the stream is still active. In order to track this potential
issue, also add an important warning log:

```cpp
srs_warn("http: try to free a alive stream, cache=%d, stream=%d", cache->alive(), stream->alive());
```

SRS may crash if got this log.

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
2024-09-01 06:44:35 +08:00
..
Architecture.md GB28181: Fix bug for parsing GB to RTC. 2022-10-07 19:47:34 +08:00
CHANGELOG.md Edge: Fix flv edge crash when http unmount. v6.0.154 v7.0.13 (#4166) 2024-09-01 06:44:35 +08:00
Dockers.md Use new cache image name. v6.0.86 (#3815) 2023-10-08 07:43:14 -05:00
Features.md WHIP: Support DELETE resource for Larix Broadcaster. v5.0.148 v6.0.36 (#3427) 2023-03-23 10:01:20 +08:00
ffmpeg-logo.png support ffmpeg filter 2013-12-01 10:54:41 +08:00
ffmpeg-min.png add drawtext filter sample 2013-12-01 12:04:00 +08:00
PERFORMANCE.md Improve README and documents with AI. v5.0.153. v6.0.43 (#3538) 2023-05-12 17:18:30 +08:00
README.md Micro changes and refines. 2022-09-30 17:57:48 +08:00
readme.txt Move doc 2020-01-26 11:14:18 +08:00
Resources.md Merge 4.0release, migrate to new website. 2022-07-31 18:34:18 +08:00
source.200kbps.768x320.flv update readme, add hls(audio-only) support to readme. update sample flv from h264+mp3 to h264+aac 2014-03-21 11:38:02 +08:00
source.flv SquashSRS4: Support RTC2RTMP. 2021-05-01 22:15:57 +08:00
srs-logo.ico Windows: Support cygwin pipline and packager. v5.0.89 (#3257) 2022-11-20 15:02:08 +08:00
srs-logo.png remove the libfreetype for it fullfill with bugs and always cause build failed. 0.9.139 2014-06-29 10:43:53 +08:00