srs/trunk/src/utest
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_utest_ai01.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_utest_ai01.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai02.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai02.hpp AI: Refine utests. 2025-10-18 23:12:59 -04:00
srs_utest_ai03.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai03.hpp AI: Refine utests. 2025-10-18 23:12:59 -04:00
srs_utest_ai04.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai04.hpp AI: Refine utests. 2025-10-18 23:12:59 -04:00
srs_utest_ai05.cpp WHIP: Return detailed HTTP error responses with proper status codes. v7.0.121 (#4502) (#4562) 2025-11-07 21:05:41 -05:00
srs_utest_ai05.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai06.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai06.hpp AI: Refine utests. 2025-10-18 23:12:59 -04:00
srs_utest_ai07.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_utest_ai07.hpp AI: Refine utests. 2025-10-18 23:12:59 -04:00
srs_utest_ai08.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_utest_ai08.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_utest_ai09.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_ai09.hpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_ai10.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_ai10.hpp AI: Refine utests. 2025-10-18 23:12:59 -04:00
srs_utest_ai11.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_ai11.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai12.cpp AI: WebRTC: Fix audio-only WHIP publish without SSRC. v7.0.132 (#4570) (#4599) 2025-12-03 09:00:16 -05:00
srs_utest_ai12.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai13.cpp Add ignore configuration for cursor. v7.0.115 (#4547) 2025-10-31 19:11:51 -04:00
srs_utest_ai13.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai14.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_utest_ai14.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_utest_ai15.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_utest_ai15.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_utest_ai16.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_utest_ai16.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_utest_ai17.cpp HLS/DASH: Fix dispose() to cleanup files after unpublish (#4618) 2026-02-03 19:36:11 -05:00
srs_utest_ai17.hpp HLS/DASH: Fix dispose() to cleanup files after unpublish (#4618) 2026-02-03 19:36:11 -05:00
srs_utest_ai18.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_utest_ai18.hpp AI: WebRTC: Support VP9 codec for WebRTC-to-WebRTC streaming. v7.0.123 (#4548) (#4565) 2025-11-08 12:47:31 -05:00
srs_utest_ai19.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_utest_ai19.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_utest_ai20.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_ai20.hpp AI: Add utest to cover signal manager 2025-10-19 22:46:06 -04:00
srs_utest_ai21.cpp AI: SRT: Fix player not exiting when publisher disconnects. v7.0.130 (#4591) (#4596) 2025-11-27 19:32:24 -05:00
srs_utest_ai21.hpp AI: SRT: Fix player not exiting when publisher disconnects. v7.0.130 (#4591) (#4596) 2025-11-27 19:32:24 -05:00
srs_utest_ai22.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_utest_ai22.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_utest_ai23.cpp AI: HLS: Support query string in hls_key_url for JWT tokens. v7.0.120 (#4426) 2025-11-06 23:00:19 -05:00
srs_utest_ai23.hpp AI: HLS: Support query string in hls_key_url for JWT tokens. v7.0.120 (#4426) 2025-11-06 23:00:19 -05:00
srs_utest_ai24.cpp HLS: Fix audio-only fMP4 playback skipping. v7.0.136 (#4602) (#4602) 2025-12-06 22:29:12 -05:00
srs_utest_ai24.hpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_manual_amf0.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_amf0.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_app_rtc2rtmp.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_manual_app_rtc2rtmp.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_app.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_app.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_avc.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_avc.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_config.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_config.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_config2.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_config2.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_core.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_core.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_coworkers.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_coworkers.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_fmp4.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_fmp4.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_gb28181.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_gb28181.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_hevc_structs.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_hevc_structs.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_http.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_http.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_kernel.cpp DVR: Fix HEVC mp4 recording error. v7.0.135 (#4604) (#4604) 2025-12-06 19:49:13 -05:00
srs_utest_manual_kernel.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_kernel2.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_kernel2.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_mock.cpp AI: WebRTC: Support optional msid attribute per RFC 8830. v7.0.126 (#4570) (#4572) 2025-11-11 10:22:31 -05:00
srs_utest_manual_mock.hpp HLS/DASH: Fix dispose() to cleanup files after unpublish (#4618) 2026-02-03 19:36:11 -05:00
srs_utest_manual_mp4.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_mp4.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_pithy_print.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_pithy_print.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_protocol.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_protocol.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_protocol2.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_utest_manual_protocol2.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_protocol3.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_protocol3.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_reload.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_reload.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_rtc_recv_track.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_manual_rtc_recv_track.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_rtc.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_manual_rtc.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_rtmp.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_rtmp.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_service.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_service.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_source_lock.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_source_lock.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_srt.cpp SRT: Support default_mode config for short streamid format. v7.0.131 (#4598) 2025-11-30 16:26:04 -05:00
srs_utest_manual_srt.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_st.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_manual_st.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_st2.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_st2.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_stream_token.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_manual_stream_token.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_forward.cpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_forward.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_http_conn.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_utest_workflow_http_conn.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_rtc_conn.cpp AI: WebRTC: Support optional msid attribute per RFC 8830. v7.0.126 (#4570) (#4572) 2025-11-11 10:22:31 -05:00
srs_utest_workflow_rtc_conn.hpp AI: WebRTC: Support VP9 codec for WebRTC-to-WebRTC streaming. v7.0.123 (#4548) (#4565) 2025-11-08 12:47:31 -05:00
srs_utest_workflow_rtc_playstream.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_workflow_rtc_playstream.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_rtc_publishstream.cpp AI: WebRTC: Report video/audio codec info and frame stats in HTTP API. v7.0.118 (#4554) 2025-11-05 21:56:16 -05:00
srs_utest_workflow_rtc_publishstream.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_rtc2rtmp.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_workflow_rtc2rtmp.hpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_workflow_rtmp_conn.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_workflow_rtmp_conn.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest_workflow_rtmp2rtc.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_workflow_rtmp2rtc.hpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest_workflow_srt_conn.cpp AI: SRT: Fix player not exiting when publisher disconnects. v7.0.130 (#4591) (#4596) 2025-11-27 19:32:24 -05:00
srs_utest_workflow_srt_conn.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00
srs_utest.cpp RTC: Fix DVR missing first 4-6 seconds by initializing rate from SDP (#4541) 2025-10-28 09:33:40 -04:00
srs_utest.hpp AI: Refine utest file rules. 2025-10-23 09:44:28 -04:00