audacity / audacity/audacity

Au3Record: failed stream start leaves stale recording state and an orphaned empty clip

Open
#11,887 0 comments 0 reactions 0 assignees View on GitHub
Task
Dominant language
C++
Stars
18.4k
Forks
2.7k
Avg merge
3d 1h
Merged PRs (30d)
78

Description

### Description

When `Au3Record::doRecord()` fails to start the audio stream (`startStream()` returns no valid token), the cleanup in the failure path is incomplete. Found while reviewing #11552 (flagged in part by CodeRabbit there).

`doRecord()` populates the recording bookkeeping *before* the stream is started:

- `m_recordData.push_back(...)` + `rebuildRecordingClipKeys()` in all three paths (existing track, deferred lead-in clip, new track) — `src/record/internal/au3/au3record.cpp`
- in the existing-track path, an empty clip is created directly **on the original track** via `insertEmptyInterval(*wt, t0, true)` and the UI is notified with `notifyAboutClipAdded()`

On failure, `cancelRecording()` only calls `PendingTracks::ClearPendingTracks()`. Two problems remain:

**1. Stale recording state**

`m_recordData` is only cleared in the `recordingFinished()` handler, which never fires when the stream failed to start. The next recording attempt appends to the stale entries. The `recordingCommitRequested()` handler iterates all of `m_recordData`; a stale entry whose clip no longer exists hits `IF_ASSERT_FAILED(origClip) { return; }` and aborts commit processing for the valid entries of the new recording as well.

Fix: clear `m_recordData` and rebuild the clip keys inside `cancelRecording()`.

**2. Orphaned empty clip on the original track**

The eagerly created clip from `insertEmptyInterval(*wt, t0, true)` lives on the original track, not on a pending track, so `ClearPendingTracks()` does not remove it and the UI was already notified about it. A failed recording start leaves an empty clip behind on the track.

Fix: remove the eagerly created clips (and send the matching UI notifications) as part of the failure cleanup.

Contributor guide

Open the contributing guide

Research direction

Start in src/record/internal/au3/au3record.cpp by tracing doRecord() into cancelRecording() and the recordingCommitRequested() handler. Verify how m_recordData, eagerly created clips, and UI notifications are handled when startStream() returns no valid token. Done means failed starts clear recording state, remove the original-track empty clips with matching notifications, and preserve later recording commits.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.