Skip to content

Commit 34e64f1

Browse files
myleshortonclaude
andcommitted
smc: revise defer Unsubscribe comment to match actual lifecycle
Per Copilot — the previous comment claimed parity with the SSE-stream-failure path, but in practice PeerConnectionEvents blocks until ctx cancellation and there's no retry loop wrapping listenPeerConnectionEvents, so the defer effectively runs at process shutdown. Rewrote to spell that out while still calling out why defer is the right shape (future-proofing against early returns / retry wrappers). No code change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 2b553c7 commit 34e64f1

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

lantern-core/core.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,15 @@ func (lc *LanternCore) listenPeerConnectionEvents() {
425425
// hit here today. Worth revisiting if Unbounded ever moves out of
426426
// process.
427427
//
428-
// defer Unsubscribe so cleanup runs on EITHER path that exits
429-
// this function: ctx cancel (normal) OR PeerConnectionEvents
430-
// returning an error (unexpected stream exit). The earlier
431-
// ctx-watching goroutine missed the error path and leaked both
432-
// the goroutine and the subscription whenever the SSE stream
433-
// died while ctx was still live.
428+
// defer Unsubscribe so cleanup runs whenever this function
429+
// returns. In practice that's process shutdown — the function
430+
// is started once from initialize(), the PeerConnectionEvents
431+
// call below blocks until ctx cancellation, and there's no
432+
// retry loop wrapping it. But if PeerConnectionEvents ever did
433+
// exit early on stream error (or a future caller adds retries),
434+
// defer keeps the subscription lifetime bound to this function's
435+
// scope rather than leaking until the next reinitialization —
436+
// which the previous ctx-watching goroutine implicitly relied on.
434437
unbSub := events.Subscribe(func(evt unbounded.ConnectionEvent) {
435438
jsonBytes, err := json.Marshal(map[string]any{
436439
"state": evt.State,

0 commit comments

Comments
 (0)