podman/libpod/runtime_worker.go
Valentin Rothberg 4a447a2133 work queue: simplify and use a wait group
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>
2022-05-25 10:17:46 +02:00

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
}()
}