Skip to content

Commit a6c1bff

Browse files
committed
port 2
1 parent c66305b commit a6c1bff

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

components/supervisor/pkg/ports/ports.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,24 @@ func (pm *Manager) updateState(ctx context.Context, exposed []ExposedPort, serve
319319

320320
status := pm.getStatus()
321321
log.WithField("ports", fmt.Sprintf("%+v", status)).Debug("ports changed")
322+
323+
// Collect subscriptions that need to be closed
324+
var toClose []*Subscription
322325
for sub := range pm.subscriptions {
323326
select {
324327
case sub.updates <- status:
325328
case <-time.After(5 * time.Second):
326329
log.Error("ports subscription droped out")
327-
_ = sub.Close()
330+
toClose = append(toClose, sub)
328331
}
329332
}
333+
334+
// Close subscriptions after releasing the lock
335+
go func() {
336+
for _, sub := range toClose {
337+
_ = sub.Close()
338+
}
339+
}()
330340
}
331341

332342
func (pm *Manager) nextState(ctx context.Context) map[uint32]*managedPort {

0 commit comments

Comments
 (0)