Aias00 opened a new pull request, #3436: URL: https://github.com/apache/dubbo-go/pull/3436
## Problem The forking cluster invoker (`cluster/cluster/forking/cluster_invoker.go`) spawns multiple goroutines to invoke providers concurrently, but only consumes the first result via `Poll(1, timeout)`. The remaining goroutines are never cancelled, causing a goroutine leak: 1. **No context cancellation**: the original `ctx` is passed to all forked goroutines, so even after the first result is returned, the other `Invoke` calls continue running indefinitely. 2. **Queue never disposed**: `resultQ` is never closed/disposed, so goroutines that complete after the first result still successfully `Put` into a queue that nobody reads from, and the queue itself is never cleaned up. 3. **Excessive error logging**: when the queue is eventually GC'd or when remaining goroutines try to `Put` after disposal, the error-level log creates noise in normal timeout scenarios. ## Fix - Use `context.WithCancel` to create a cancellable `forkCtx`; `defer cancel()` so all forked goroutines are signaled to stop when `Invoke` returns. - Pass `forkCtx` instead of `ctx` to forked goroutines so their `Invoke` calls respect the cancellation. - Call `resultQ.Dispose()` immediately after `Poll` to release queue resources and make remaining goroutines' `Put` calls return `ErrDisposed` promptly. - Downgrade `Put` error log from `Errorf` to `Debugf` since `ErrDisposed` is an expected condition after the queue is disposed. ## Testing All existing tests pass with no regression: ``` ok dubbo.apache.org/dubbo-go/v3/cluster/cluster/forking ok dubbo.apache.org/dubbo-go/v3/cluster/... (all sub-packages) ``` Co-Authored-By: Claude <[email protected]> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
