Skip to content

fix: serialise stream lifecycle + self-heal zombie streams (A-5, A-6, C-1)#12

Merged
ntt0601zcoder merged 1 commit into
mainfrom
fix/lifecycle-self-heal
Jun 13, 2026
Merged

fix: serialise stream lifecycle + self-heal zombie streams (A-5, A-6, C-1)#12
ntt0601zcoder merged 1 commit into
mainfrom
fix/lifecycle-self-heal

Conversation

@ntt0601zcoder

Copy link
Copy Markdown
Owner

Fixes audit findings A-5, A-6, C-1 — the 'zombie stream' cluster (stream reports Active/IsRunning=true but is dead/output-less, so the reconciler skips it and it never self-heals).

  • C-1 — no per-stream serialisation of Start/Stop/Update: a racing op's rollback tore down another op's buffers / manager registration (keyed only by code) and leaked monitor goroutines. Added a per-stream lifecycle mutex wrapping the full body (startLocked/stopLocked/updateLocked so re-entrant internal calls don't deadlock); racing ops re-check IsRunning and no-op. manager.Register refuses duplicate registration.
  • A-5manager.Register only logged a synchronous ingest-start failure → permanent zombie reported Active. Now routes through ReportInputError (degrade → failover/exhausted): multi-input promotes a backup, single-input flips to Degraded + probe loop.
  • A-6reloadTranscoderFull returned early on a mid-flight start failure, stranding the stream with no publisher/DVR but IsRunning=true. Now falls back to a full Stop → reconciler restarts from persisted config within one tick (≤10 s self-heal).

Tests: TestLifecycle_ConcurrentStartStopSerialised (-race), TestUpdate_ReloadFailureFullStops, TestRegister_StartFailureDrivesExhausted, TestRegister_RefusesDuplicate. go build, go test -race (coordinator+manager), golangci-lint all green. Findings flipped to ✅ in the audit report.

Noted follow-up: the connects-but-sends-no-packets Idle blind spot (A-5).

Three 'zombie stream' bugs where a stream reported Active/IsRunning=true but
was dead or output-less, and the reconciler skipped it (IsRunning) so it never
self-healed:

- C-1: Start/Stop/Update had no per-stream serialisation, so a racing op's
  rollback tore down another op's buffers / manager registration (keyed only
  by code) and leaked monitor goroutines. Added a per-stream lifecycle mutex
  wrapping the full body (startLocked/stopLocked/updateLocked so re-entrant
  internal calls don't deadlock); racing ops re-check IsRunning and no-op.
- A-5: manager.Register only logged a synchronous ingest start failure and
  returned nil. It now routes through ReportInputError (degrade → failover /
  exhausted) and refuses a duplicate registration (no goroutine leak).
- A-6: reloadTranscoderFull returned early on a mid-flight start failure,
  leaving the stream with no publisher/DVR but IsRunning=true. It now falls
  back to a full Stop so the reconciler restarts it within one tick.

Regression tests for each (C-1 under -race). Fixes audit findings A-5, A-6, C-1.
@ntt0601zcoder ntt0601zcoder merged commit 1d7501a into main Jun 13, 2026
4 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.87755% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/coordinator/coordinator.go 93.18% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ntt0601zcoder ntt0601zcoder deleted the fix/lifecycle-self-heal branch June 13, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants