File tree 2 files changed +29
-3
lines changed 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -2043,7 +2043,7 @@ function speedList(code) {
2043
2043
return setTimeout ( speedList , 1400 ) ;
2044
2044
}
2045
2045
console . error ( 'Error retrieving process list: %s.\nA process seems to be on infinite loop, retry in 5 seconds' , err ) ;
2046
- exitCli ( cst . ERROR_EXIT ) ;
2046
+ return exitCli ( cst . ERROR_EXIT ) ;
2047
2047
}
2048
2048
if ( commander . miniList && ! commander . silent )
2049
2049
UX . miniDisplay ( list ) ;
@@ -2061,7 +2061,7 @@ function speedList(code) {
2061
2061
return CLI . streamLogs ( null , 1 ) ;
2062
2062
}
2063
2063
else {
2064
- // return exitCli(code ? code : cst.SUCCESS_EXIT);
2064
+ return exitCli ( code ? code : cst . SUCCESS_EXIT ) ;
2065
2065
}
2066
2066
} ) ;
2067
2067
}
Original file line number Diff line number Diff line change @@ -187,7 +187,33 @@ Common.formatCLU = function(csp) {
187
187
Common . exitCli = function ( code ) {
188
188
InteractorDaemonizer . disconnectRPC ( function ( ) {
189
189
Satan . disconnectRPC ( function ( ) {
190
- process . exit ( code || 0 ) ;
190
+ code = code || 0 ;
191
+ // Safe exits process after all streams are drained.
192
+ // file descriptor flag.
193
+ var fds = 0 ;
194
+ // exits process when stdout (1) and sdterr(2) are both drained.
195
+ function tryToExit ( ) {
196
+ if ( ( fds & 1 ) && ( fds & 2 ) ) {
197
+ process . exit ( code ) ;
198
+ }
199
+ }
200
+
201
+ [ process . stdout , process . stderr ] . forEach ( function ( std ) {
202
+ var fd = std . fd ;
203
+ if ( ! std . bufferSize ) {
204
+ // bufferSize equals 0 means current stream is drained.
205
+ fds = fds | fd ;
206
+ } else {
207
+ // Appends nothing to the std queue, but will trigger `tryToExit` event on `drain`.
208
+ std . write && std . write ( '' , function ( ) {
209
+ fds = fds | fd ;
210
+ tryToExit ( ) ;
211
+ } ) ;
212
+ }
213
+ // Does not write anything more.
214
+ delete std . write ;
215
+ } ) ;
216
+ tryToExit ( ) ;
191
217
} ) ;
192
218
} ) ;
193
219
} ;
You can’t perform that action at this time.
0 commit comments