11/*
2- © Copyright IBM Corporation 2017, 2023
2+ © Copyright IBM Corporation 2017, 2024
33
44Licensed under the Apache License, Version 2.0 (the "License");
55you may not use this file except in compliance with the License.
@@ -52,12 +52,21 @@ func signalHandler(qmgr string, startupCtx context.Context) chan int {
5252
5353 // Start handling signals
5454 go func () {
55+ shutdownCtx , shutdownComplete := context .WithCancel (context .Background ())
56+ defer func () {
57+ shutdownComplete ()
58+ }()
59+ stopTriggered := false
5560 for {
5661 select {
5762 case sig := <- stopSignals :
63+ if stopTriggered {
64+ continue
65+ }
5866 log .Printf ("Signal received: %v" , sig )
59- signal .Stop (reapSignals )
6067 signal .Stop (stopSignals )
68+ stopTriggered = true
69+
6170 // If a stop signal is received during the startup process continue processing control signals until the main thread marks startup as complete
6271 // Don't close the control channel until the main thread has been allowed to finish spawning processes and marks startup as complete
6372 // Continue to process job control signals to avoid a deadlock
@@ -73,8 +82,15 @@ func signalHandler(qmgr string, startupCtx context.Context) chan int {
7382 }
7483 }
7584 metrics .StopMetricsGathering (log )
76- // #nosec G104
77- stopQueueManager (qmgr )
85+
86+ // Shutdown queue manager in separate goroutine to allow reaping to continue in parallel
87+ go func () {
88+ _ = stopQueueManager (qmgr )
89+ shutdownComplete ()
90+ }()
91+ case <- shutdownCtx .Done ():
92+ signal .Stop (reapSignals )
93+
7894 // One final reap
7995 // This occurs after all startup processes have been spawned
8096 reapZombies ()
0 commit comments