fix(whip): wire teardown hook in NewWHIPHandler constructor (mirrors WHEP NewHandler pattern)
Some checks failed
ci / vet + build (push) Failing after 5m1s
ci / race tests (push) Has been skipped
ci / WebRTC smoke (5-viewer fanout) (push) Has been skipped
ci / WebRTC latency p95 gate (push) Has been skipped

This commit is contained in:
Zac Gaetano 2026-05-09 16:38:29 -04:00
parent 1be78a8185
commit 7f545962f6

View file

@ -36,6 +36,10 @@ type WHIPHandler struct {
// NewWHIPHandler wraps the subsystem in an Echo-compatible WHIP handler.
// maxPublishers caps concurrent ingest sessions across all streams;
// pass 0 to default to 64.
//
// The constructor registers a teardown hook on the Subsystem so that
// when a process stops, any active WHIP publisher is closed automatically
// (mirroring the pattern used by the WHEP NewHandler).
func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler {
total := int64(maxPublishers)
if total <= 0 {
@ -47,6 +51,12 @@ func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler {
ingestStream: make(map[string]string),
maxCapTotal: total,
}
// Wire the WHIP teardown hook so onWHIPProcessStop notifies us
// before releasing the port allocation — same pattern as WHEP's
// NewHandler → s.SetTeardownHook(h.tearDownStreamPeers).
if s != nil {
s.SetWHIPTeardownHook(h.tearDownStreamIngests)
}
return h
}
@ -313,8 +323,9 @@ func (h *WHIPHandler) awaitIngestClose(resource string, peer *corewebrtc.IngestP
}
}
// tearDownStreamIngests is called by the Subsystem's onWHIPProcessStop
// hook to close any active publisher when the FFmpeg process stops.
// tearDownStreamIngests is called by the Subsystem's SetWHIPTeardownHook
// to close any active publisher when the FFmpeg process stops.
// Not exported — registered internally via NewWHIPHandler.
func (h *WHIPHandler) tearDownStreamIngests(streamID string) {
h.mu.Lock()
bucket := h.ingestByStream[streamID]