srs/trunk/src/app
hyunwoo jo 6e2392f366
HLS/DASH: Fix dispose() to cleanup files after unpublish (#4618)
# HLS/DASH: Fix dispose() to cleanup files after unpublish

## Summary
Fixes a bug where HLS/DASH files are not deleted after the configured
`hls_dispose`/`dash_dispose` timeout.

## Problem
When a stream is unpublished:
1. `on_unpublish()` is called and sets `enabled_ = false`
2. After the dispose timeout, `cycle()` calls `dispose()`
3. `dispose()` immediately returns due to `if (!enabled_)` check at line
2722 (HLS) and line 891 (DASH)
4. `controller_->dispose()` is never called
5. Files remain on disk indefinitely

**Observed behavior**:
- Stream stopped at 11:32:42
- `dispose()` called at 11:33:14 (after 30s timeout)
- Log shows "hls cycle to dispose hls" but no "gracefully dispose hls"
message
- Files remain on disk

## Root Cause
Commit 550760f2d introduced an early return in `dispose()` when
`!enabled_`, which prevents file cleanup after `on_unpublish()` has
already been called and set `enabled_` to false.

## Solution
Reorder the logic in `dispose()` to:
1. Check if dispose is enabled (hls_dispose/dash_dispose > 0) first
2. Call `on_unpublish()` only if `enabled_` is still true (prevents
duplicate calls)
3. Always call `controller_->dispose()` to cleanup files when dispose
timeout occurs

This ensures files are properly cleaned up while still preventing
duplicate `on_unpublish()` calls.

## Changes Made
- **trunk/src/app/srs_app_hls.cpp** (lines 2718-2734): Reordered
dispose() logic
- **trunk/src/app/srs_app_dash.cpp** (lines 887-902): Reordered
dispose() logic
- **trunk/doc/CHANGELOG.md**: Added v7.0.137 entry

## Testing Recommendation

To verify the fix:

1. Start RTMP stream to `/live/test`:
   ```bash
   ffmpeg -re -i test.mp4 -c copy -f flv rtmp://localhost:1935/live/test
   ```

2. Wait for HLS segments to be created:
   ```bash
   ls -la /path/to/hls/live/test/
   ```

3. Stop the stream (Ctrl+C)

4. Wait for `hls_dispose` timeout (default 120s, or 30s with your
config):
   ```bash
# Watch logs for "hls cycle to dispose hls" and "gracefully dispose hls"
   tail -f srs.log
   ```

5. Verify files are deleted:
   ```bash
   ls -la /path/to/hls/live/test/
   # Should be empty or directory removed
   ```

**Expected results**:
- Before fix: Files remain on disk
- After fix: Files are deleted, logs show "gracefully dispose hls"

## Impact
- **Risk**: Low - minimal logic change, only reordering of checks
- **Breaking changes**: None
- **Performance**: No impact
- **Compatibility**: Fixes existing bug, improves expected behavior

## Checklist
- [x] Code follows project style
- [x] Both HLS and DASH are fixed
- [x] CHANGELOG updated
- [x] Tested locally (recommended before merge)
- [x] No breaking changes

## Related Issues
- Regression introduced in: 550760f2d
- Related to: #865 (hls_dispose feature)

---------

Co-authored-by: Jacob Su <suzp1984@gmail.com>
2026-02-03 19:36:11 -05:00
..
srs_app_async_call.cpp AI: Add utest to cover app server module. 2025-10-04 09:06:03 -04:00
srs_app_async_call.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_caster_flv.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_caster_flv.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_circuit_breaker.cpp AI: Add utest to cover heatbeat. 2025-10-15 09:59:45 -04:00
srs_app_circuit_breaker.hpp AI: Add utest to cover heatbeat. 2025-10-15 09:59:45 -04:00
srs_app_config.cpp SRT: Support default_mode config for short streamid format. v7.0.131 (#4598) 2025-11-30 16:26:04 -05:00
srs_app_config.hpp SRT: Support default_mode config for short streamid format. v7.0.131 (#4598) 2025-11-30 16:26:04 -05:00
srs_app_coworkers.cpp AI: Improve utest coverage. 2025-10-29 08:09:40 -04:00
srs_app_coworkers.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_dash.cpp HLS/DASH: Fix dispose() to cleanup files after unpublish (#4618) 2026-02-03 19:36:11 -05:00
srs_app_dash.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_dvr.cpp AI: Add utest to cover hooks module. 2025-10-10 11:43:24 -04:00
srs_app_dvr.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_edge.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_edge.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_encoder.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_encoder.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_factory.cpp HLS: Fix audio-only fMP4 playback skipping. v7.0.136 (#4602) (#4602) 2025-12-06 22:29:12 -05:00
srs_app_factory.hpp HLS: Fix audio-only fMP4 playback skipping. v7.0.136 (#4602) (#4602) 2025-12-06 22:29:12 -05:00
srs_app_ffmpeg.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_ffmpeg.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_forward.cpp AI: Add utest to cover forwarding module. #4531 2025-10-21 23:33:29 -04:00
srs_app_forward.hpp AI: Add utest to cover forwarding module. #4531 2025-10-21 23:33:29 -04:00
srs_app_fragment.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_fragment.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_gb28181.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_gb28181.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_hds.cpp AI: Improve coverage for app rtmp module. 2025-10-03 10:10:57 -04:00
srs_app_hds.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_heartbeat.cpp AI: Add utest to cover heatbeat. 2025-10-15 09:59:45 -04:00
srs_app_heartbeat.hpp AI: Add utest to cover heatbeat. 2025-10-15 09:59:45 -04:00
srs_app_hls.cpp HLS/DASH: Fix dispose() to cleanup files after unpublish (#4618) 2026-02-03 19:36:11 -05:00
srs_app_hls.hpp HLS: Fix audio-only fMP4 playback skipping. v7.0.136 (#4602) (#4602) 2025-12-06 22:29:12 -05:00
srs_app_http_api.cpp AI: API: Change pagination default count to 10, minimum 1. v7.0.128 (#4584) 2025-11-18 12:12:16 -05:00
srs_app_http_api.hpp AI: API: Change pagination default count to 10, minimum 1. v7.0.128 (#4584) 2025-11-18 12:12:16 -05:00
srs_app_http_client.cpp Use clang format. v7.0.52 (#4433) 2025-08-11 23:19:19 -04:00
srs_app_http_client.hpp Use clang format. v7.0.52 (#4433) 2025-08-11 23:19:19 -04:00
srs_app_http_conn.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_http_conn.hpp AI: Add workflow test for HTTP conn 2025-10-19 19:10:52 -04:00
srs_app_http_hooks.cpp AI: API: Add clients field to on_play/on_stop webhooks and total field to HTTP API. v7.0.107 (#4147) 2025-10-26 16:28:22 -04:00
srs_app_http_hooks.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_http_static.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_http_static.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_http_stream.cpp AI: HTTP-FLV: Enforce minimum 10ms sleep to prevent CPU busy-wait when mw_latency=0. v7.0.110 (#3963) 2025-10-26 20:17:46 -04:00
srs_app_http_stream.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_ingest.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_ingest.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_latest_version.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_latest_version.hpp AI: Add utest to cover version query 2025-10-15 09:11:04 -04:00
srs_app_listener.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_listener.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_log.cpp AI: WebRTC: Support G.711 (PCMU/PCMA) audio codec for WebRTC. v7.0.124 (#4075) (#4568) 2025-11-09 12:08:03 -05:00
srs_app_log.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_mpegts_udp.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_mpegts_udp.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_ng_exec.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_ng_exec.hpp AI: Add utest to cover version query 2025-10-15 09:11:04 -04:00
srs_app_process.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_process.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_recv_thread.cpp AI: API: Add audio_frames and video_frames to HTTP API. v7.0.122 (#4559) (#4564) 2025-11-07 22:32:26 -05:00
srs_app_recv_thread.hpp AI: API: Add audio_frames and video_frames to HTTP API. v7.0.122 (#4559) (#4564) 2025-11-07 22:32:26 -05:00
srs_app_refer.cpp Update stable version to SRS 6.0 2025-09-15 11:23:02 -04:00
srs_app_refer.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_reload.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_reload.hpp AI: Remove most of reload, only keep framework. (#4458) 2025-08-30 09:44:37 -04:00
srs_app_rtc_api.cpp AI: Fix race condition causing immediate deletion of new sources. v7.0.127 (#4449) (#4576) 2025-11-13 21:24:07 -05:00
srs_app_rtc_api.hpp WHIP: Return detailed HTTP error responses with proper status codes. v7.0.121 (#4502) (#4562) 2025-11-07 21:05:41 -05:00
srs_app_rtc_codec.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_app_rtc_codec.hpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_app_rtc_conn.cpp AI: WebRTC: Fix audio-only WHIP publish without SSRC. v7.0.132 (#4570) (#4599) 2025-12-03 09:00:16 -05:00
srs_app_rtc_conn.hpp AI: API: Add audio_frames and video_frames to HTTP API. v7.0.122 (#4559) (#4564) 2025-11-07 22:32:26 -05:00
srs_app_rtc_dtls.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_rtc_dtls.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_rtc_network.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_rtc_network.hpp AI: Add workflow utest for rtc conn. 2025-10-17 21:55:29 -04:00
srs_app_rtc_server.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_rtc_server.hpp AI: WebRTC: Support G.711 (PCMU/PCMA) audio codec for WebRTC. v7.0.124 (#4075) (#4568) 2025-11-09 12:08:03 -05:00
srs_app_rtc_source.cpp AI: Fix race condition causing immediate deletion of new sources. v7.0.127 (#4449) (#4576) 2025-11-13 21:24:07 -05:00
srs_app_rtc_source.hpp AI: RTC: Support keep_original_ssrc to preserve SSRC and timestamps. v7.0.119 (#3850) 2025-11-06 21:45:50 -05:00
srs_app_rtmp_conn.cpp RTMP: Ignore FMLE start packet after flash publish. v7.0.129 (#4588) 2025-11-27 09:28:46 -05:00
srs_app_rtmp_conn.hpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_rtmp_source.cpp AI: Fix race condition causing immediate deletion of new sources. v7.0.127 (#4449) (#4576) 2025-11-13 21:24:07 -05:00
srs_app_rtmp_source.hpp AI: Add utest to cover forwarding module. #4531 2025-10-21 23:33:29 -04:00
srs_app_rtsp_conn.cpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_rtsp_conn.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_rtsp_source.cpp AI: Fix race condition causing immediate deletion of new sources. v7.0.127 (#4449) (#4576) 2025-11-13 21:24:07 -05:00
srs_app_rtsp_source.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_security.cpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_security.hpp AI: Add workflow utest for RTMP conn 2025-10-18 22:13:15 -04:00
srs_app_server.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_app_server.hpp AI: Ignore some code that is no need to cover. 2025-10-28 23:10:31 -04:00
srs_app_srt_conn.cpp SRT: Fix peer_idle_timeout not applied to publishers and players. v7.0.134 (#4600) (#4606) 2025-12-06 17:26:49 -05:00
srs_app_srt_conn.hpp AI: Add workflow utest for SRT conn 2025-10-19 13:23:20 -04:00
srs_app_srt_listener.cpp Use clang format. v7.0.52 (#4433) 2025-08-11 23:19:19 -04:00
srs_app_srt_listener.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_srt_server.cpp AI: Improve utest coverage. 2025-10-29 08:09:40 -04:00
srs_app_srt_server.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_srt_source.cpp AI: SRT: Fix player not exiting when publisher disconnects. v7.0.130 (#4591) (#4596) 2025-11-27 19:32:24 -05:00
srs_app_srt_source.hpp AI: SRT: Fix player not exiting when publisher disconnects. v7.0.130 (#4591) (#4596) 2025-11-27 19:32:24 -05:00
srs_app_st.cpp Fix WHIP with transcoding bug. v7.0.92 (#4495) 2025-09-21 08:58:22 -04:00
srs_app_st.hpp AI: Add utest to cover process module 2025-10-15 07:52:46 -04:00
srs_app_statistic.cpp AI: WebRTC: Support G.711 (PCMU/PCMA) audio codec for WebRTC. v7.0.124 (#4075) (#4568) 2025-11-09 12:08:03 -05:00
srs_app_statistic.hpp AI: API: Add audio_frames and video_frames to HTTP API. v7.0.122 (#4559) (#4564) 2025-11-07 22:32:26 -05:00
srs_app_stream_bridge.cpp AI: SRT: Report video/audio codec info and frame stats in HTTP API. v7.0.117 (#4554) 2025-11-04 10:41:11 -05:00
srs_app_stream_bridge.hpp AI: SRT: Report video/audio codec info and frame stats in HTTP API. v7.0.117 (#4554) 2025-11-04 10:41:11 -05:00
srs_app_stream_token.cpp AI: Add workflow utest for rtc conn. 2025-10-17 21:55:29 -04:00
srs_app_stream_token.hpp AI: Add workflow utest for rtc conn. 2025-10-17 21:55:29 -04:00
srs_app_utility.cpp AI: Improve utest coverage. 2025-10-29 08:09:40 -04:00
srs_app_utility.hpp AI: Add utest to cover heatbeat. 2025-10-15 09:59:45 -04:00