Skip to content

Commit 3026c2c

Browse files
committed
fix(envd): grab subSignal before checking conditions in receiveWhenReady
Avoids a race where a subscriber added between HasSubscribers() and fetching subSignal could leave the fan-out parked on a fresh unclosed signal channel.
1 parent c55adcc commit 3026c2c

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

packages/envd/internal/services/process/handler/multiplex.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,13 @@ func (m *MultiplexedChannel[T]) run() {
115115
// so the fan-out loop wakes up and observes the closed channel.
116116
func (m *MultiplexedChannel[T]) receiveWhenReady() (v T, ok bool) {
117117
for {
118-
if m.HasSubscribers() {
119-
v, ok = <-m.Source
120-
121-
return v, ok
122-
}
123-
124-
// No active subscribers — wait for a change notification.
118+
// Grab the signal before checking conditions so any change
119+
// that happens after the check closes the channel we wait on.
125120
m.subMu.Lock()
126121
sig := m.subSignal
127122
m.subMu.Unlock()
128123

129-
if m.closed.Load() {
124+
if m.HasSubscribers() || m.closed.Load() {
130125
v, ok = <-m.Source
131126

132127
return v, ok

0 commit comments

Comments
 (0)