Browse Source

Prevent goroutine leaks by adding timeouts to blocking cmds sends

Add 2-second timeouts to both handleStreamError and the async fallback goroutine
when sending ActionStreamError to cmds channel. This prevents the handleOutgoing
and handleIncoming goroutines from blocking indefinitely if the managerLoop is
no longer receiving (e.g., during shutdown), preventing resource leaks.
pull/7838/head
Chris Lu 2 months ago
parent
commit
7e0664aee9
  1. 12
      weed/worker/client.go

12
weed/worker/client.go

@ -360,7 +360,11 @@ func handleOutgoing(
handleStreamError := func(err error) { handleStreamError := func(err error) {
if err != nil { if err != nil {
glog.Errorf("Failed to send message to admin: %v", err) glog.Errorf("Failed to send message to admin: %v", err)
cmds <- grpcCommand{action: ActionStreamError, data: err}
select {
case cmds <- grpcCommand{action: ActionStreamError, data: err}:
case <-time.After(2 * time.Second):
glog.Warningf("Failed to send stream error to manager from outgoing handler, channel blocked: %v", err)
}
} }
} }
@ -470,7 +474,11 @@ func handleIncoming(
default: default:
glog.V(2).Infof("Manager busy, queuing stream error asynchronously: %v", err) glog.V(2).Infof("Manager busy, queuing stream error asynchronously: %v", err)
go func(e error) { go func(e error) {
cmds <- grpcCommand{action: ActionStreamError, data: e}
select {
case cmds <- grpcCommand{action: ActionStreamError, data: e}:
case <-time.After(2 * time.Second):
glog.Warningf("Failed to send stream error to manager, channel blocked: %v", e)
}
}(err) }(err)
} }

Loading…
Cancel
Save