Tags: cilium/workerpool
Tags
add NewWithContext Before this patch, forwarding context cancellation to the workerpool tasks was difficult and required to spawn a goroutine to call wp.Close when the parent context was done. This patch introduce NewWithContext allowing callers to provide a parent context from which is derived the tasks context, removing the need to manually forward context cancellation. Signed-off-by: Alexandre Perrin <alex@isovalent.com>
workerpool: WaitGroup synchronization fix Before this patch, Submit() would increment the WaitGroup without holding the WorkerPool lock. This could potentially lead to a panic when Submit() and Close() were executed concurrently: 1. The Submit() goroutine g0 acquire the lock, successfully check that the WorkerPool is neither closed nor draining, and release the lock. 2. The Close() goroutine g1 acquire the lock, update the WorkerPool state to closed, wait on the WaitGroup, and close the tasks channel (wrongly) assuming that all tasks have been submitted. 3. g0 increment the WaitGroup, and attempt to write to the (now closed) tasks channel leading to a panic. The same reasoning can be applied with Submit() and Drain() leading to a data race on the results slice. Signed-off-by: Alexandre Perrin <alex@kaworu.ch>