mirror of
https://github.com/containers/podman.git
synced 2025-05-21 00:56:36 +08:00

Simplify the work-queue implementation by using a wait group. Once all queued work items are done, the channel can be closed. The system tests revealed a flake (i.e., #14351) which indicated that the service container does not always get stopped which suggests a race condition when queuing items. Those items are queued in a goroutine to prevent potential dead locks if the queue ever filled up too quickly. The race condition in question is that if a work item queues another, the goroutine for queuing may not be scheduled fast enough and the runtime shuts down; it seems to happen fairly easily on the slow CI machines. The wait group fixes this race and allows for simplifying the code. Also increase the queue's buffer size to 10 to make things slightly faster. [NO NEW TESTS NEEDED] as we are fixing a flake. Fixes: #14351 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
19 lines
287 B
Go
19 lines
287 B
Go
package libpod
|
|
|
|
func (r *Runtime) startWorker() {
|
|
r.workerChannel = make(chan func(), 10)
|
|
go func() {
|
|
for w := range r.workerChannel {
|
|
w()
|
|
r.workerGroup.Done()
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (r *Runtime) queueWork(f func()) {
|
|
r.workerGroup.Add(1)
|
|
go func() {
|
|
r.workerChannel <- f
|
|
}()
|
|
}
|