@@ -14,6 +14,7 @@ import (
14
14
"golang.org/x/sync/errgroup"
15
15
16
16
"github.com/ava-labs/avalanchego/node"
17
+ "github.com/ava-labs/avalanchego/utils"
17
18
"github.com/ava-labs/avalanchego/utils/logging"
18
19
"github.com/ava-labs/avalanchego/utils/perms"
19
20
"github.com/ava-labs/avalanchego/utils/ulimit"
@@ -90,26 +91,40 @@ func Run(app App) int {
90
91
return 1
91
92
}
92
93
93
- // register signals to kill the application
94
- signals := make (chan os.Signal , 1 )
95
- signal .Notify (signals , syscall .SIGINT )
96
- signal .Notify (signals , syscall .SIGTERM )
94
+ // register terminationSignals to kill the application
95
+ terminationSignals := make (chan os.Signal , 1 )
96
+ signal .Notify (terminationSignals , syscall .SIGINT , syscall .SIGTERM )
97
+
98
+ stackTraceSignal := make (chan os.Signal , 1 )
99
+ signal .Notify (stackTraceSignal , syscall .SIGABRT )
97
100
98
101
// start up a new go routine to handle attempts to kill the application
99
102
var eg errgroup.Group
100
103
eg .Go (func () error {
101
- for range signals {
104
+ for range terminationSignals {
102
105
return app .Stop ()
103
106
}
104
107
return nil
105
108
})
106
109
110
+ // start a goroutine to listen on SIGABRT signals,
111
+ // to print the stack trace to standard error.
112
+ go func () {
113
+ for range stackTraceSignal {
114
+ fmt .Fprint (os .Stderr , utils .GetStacktrace (true ))
115
+ }
116
+ }()
117
+
107
118
// wait for the app to exit and get the exit code response
108
119
exitCode , err := app .ExitCode ()
109
120
110
- // shut down the signal go routine
111
- signal .Stop (signals )
112
- close (signals )
121
+ // shut down the termination signal go routine
122
+ signal .Stop (terminationSignals )
123
+ close (terminationSignals )
124
+
125
+ // shut down the stack trace go routine
126
+ signal .Stop (stackTraceSignal )
127
+ close (stackTraceSignal )
113
128
114
129
// if there was an error closing or running the application, report that error
115
130
if eg .Wait () != nil || err != nil {
0 commit comments