create runtime's worker queue before queuing any job

It seems that if some background tasks are queued in libpod's Runtime before the worker's channel is set up (eg. in the refresh phase), they are not executed later on, but the workerGroup's counter is still ticked up. This leads podman to hang when the imageEngine is shutdown, since it waits for the workerGroup to be done.

fixes containers/podman#22984

Signed-off-by: Farya Maerten <me@ltow.me>
This commit is contained in:
Farya L. Maerten
2024-06-12 17:26:47 +02:00
committed by Farya Maerten
parent abf0350529
commit c819c7a973
2 changed files with 9 additions and 1 deletions

View File

@ -613,6 +613,11 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
// refresh runs.
runtime.valid = true
// Setup the worker channel early to start accepting jobs from refresh,
// but do not start to execute the jobs right away. The runtime is not
// ready at this point.
runtime.setupWorkerQueue()
// If we need to refresh the state, do it now - things are guaranteed to
// be set up by now.
if doRefresh {

View File

@ -2,8 +2,11 @@
package libpod
func (r *Runtime) startWorker() {
func (r *Runtime) setupWorkerQueue() {
r.workerChannel = make(chan func(), 10)
}
func (r *Runtime) startWorker() {
go func() {
for w := range r.workerChannel {
w()