From 7f545962f6e1d97d2685cb9d74cb110a55e44ef9 Mon Sep 17 00:00:00 2001 From: ZGaetano Date: Sat, 9 May 2026 16:38:29 -0400 Subject: [PATCH] fix(whip): wire teardown hook in NewWHIPHandler constructor (mirrors WHEP NewHandler pattern) --- app/webrtc/whip_handler.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/webrtc/whip_handler.go b/app/webrtc/whip_handler.go index 1924371..fb3bfb4 100644 --- a/app/webrtc/whip_handler.go +++ b/app/webrtc/whip_handler.go @@ -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]