From fe3591bd8a96873abc98bb9d2d5c62f27efca3e9 Mon Sep 17 00:00:00 2001 From: berbreik Date: Sat, 11 Jan 2025 04:45:34 +0530 Subject: [PATCH] sync/errgroup: improve documentation for semaphore limit behavior Updated the documentation for `SetLimit` and `Go` functions in the `errgroup` package. the note clarifies the behavior when the semaphore limit is set to zero, which could lead to a deadlock if not handled properly. the updated documentation warns users to set a positive semaphore limit to avoid blocking goroutines and potential deadlock this change improves the clarity of API and helps users understand how to properly use the semaphore limit to prevent issues in concurrent execution Change-Id: Ie62acc38ef804b3590c04bddba00a3cce21e8cef Reviewed-on: https://go-review.googlesource.com/c/sync/+/642215 Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- errgroup/errgroup.go | 1 + 1 file changed, 1 insertion(+) diff --git a/errgroup/errgroup.go b/errgroup/errgroup.go index 948a3ee..b832259 100644 --- a/errgroup/errgroup.go +++ b/errgroup/errgroup.go @@ -118,6 +118,7 @@ func (g *Group) TryGo(f func() error) bool { // SetLimit limits the number of active goroutines in this group to at most n. // A negative value indicates no limit. +// A limit of zero will prevent any new goroutines from being added. // // Any subsequent call to the Go method will block until it can add an active // goroutine without exceeding the configured limit.