Skip to content

fix: prevent duplicate stream terminal events - #224

Merged
1Lucas1apk merged 1 commit into
PerformanC:devfrom
shhahbaz:fix/prevent-duplicate-stream-events
Aug 23, 2026
Merged

fix: prevent duplicate stream terminal events#224
1Lucas1apk merged 1 commit into
PerformanC:devfrom
shhahbaz:fix/prevent-duplicate-stream-events

Conversation

@shhahbaz

Copy link
Copy Markdown

Changes

  • Make PCM stream terminal handling idempotent.
  • Prevent duplicate end/error notifications when streams emit both terminal and close events.
  • Make active stream cleanup safe when cancellation is followed by a late close event.
  • Track cleaned stream entries explicitly.
  • Count cancellation exactly once.
  • Add regression tests for end/close, error/close, and cancellation races.

Why

Readable streams commonly emit end followed by close. The worker previously attached terminal handlers to both events without guarding against repeated execution. This could send duplicate stream completion frames, increment lifecycle counters incorrectly, and run cleanup more than once.

Cancellation had a related race where the stream was cleaned immediately, then a later close event performed terminal handling again.

This fix ensures each stream has exactly one terminal outcome and exactly one cleanup operation without changing the Lavalink-compatible stream protocol.

Checkmarks

  • The modified endpoints have been tested.
  • Used the same indentation as the rest of the project.
  • Still compatible with LavaLink clients.

Additional information

  • No new test framework or runtime dependency was introduced.
  • The finalizer is limited to worker PCM stream lifecycle handling.

@1Lucas1apk
1Lucas1apk merged commit a92eb23 into PerformanC:dev Aug 23, 2026
1 check passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 23, 2026
@1Lucas1apk

Copy link
Copy Markdown
Member

Thanks for your contribution :P

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants