1
1
/*
2
- © Copyright IBM Corporation 2017, 2023
2
+ © Copyright IBM Corporation 2017, 2024
3
3
4
4
Licensed under the Apache License, Version 2.0 (the "License");
5
5
you may not use this file except in compliance with the License.
@@ -52,12 +52,21 @@ func signalHandler(qmgr string, startupCtx context.Context) chan int {
52
52
53
53
// Start handling signals
54
54
go func () {
55
+ shutdownCtx , shutdownComplete := context .WithCancel (context .Background ())
56
+ defer func () {
57
+ shutdownComplete ()
58
+ }()
59
+ stopTriggered := false
55
60
for {
56
61
select {
57
62
case sig := <- stopSignals :
63
+ if stopTriggered {
64
+ continue
65
+ }
58
66
log .Printf ("Signal received: %v" , sig )
59
- signal .Stop (reapSignals )
60
67
signal .Stop (stopSignals )
68
+ stopTriggered = true
69
+
61
70
// If a stop signal is received during the startup process continue processing control signals until the main thread marks startup as complete
62
71
// Don't close the control channel until the main thread has been allowed to finish spawning processes and marks startup as complete
63
72
// Continue to process job control signals to avoid a deadlock
@@ -73,8 +82,15 @@ func signalHandler(qmgr string, startupCtx context.Context) chan int {
73
82
}
74
83
}
75
84
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
+
78
94
// One final reap
79
95
// This occurs after all startup processes have been spawned
80
96
reapZombies ()
0 commit comments