@@ -932,8 +932,18 @@ export function _runTaskList(
932
932
} ) ;
933
933
try {
934
934
logger . debug ( `Attempting forceful shutdown` ) ;
935
+ const timeout = new Promise ( ( _resolve , reject ) => {
936
+ const t = setTimeout (
937
+ ( ) => reject ( new Error ( "Timed out" ) ) ,
938
+ 5000 /* TODO: make configurable */ ,
939
+ ) ;
940
+ t . unref ( ) ;
941
+ } ) ;
942
+
935
943
// Stop new jobs being added
936
- const deactivatePromise = deactivate ( ) ;
944
+ // NOTE: deactivate() immediately stops getJob working, even if the
945
+ // promise takes a while to resolve.
946
+ const deactivatePromise = Promise . race ( [ deactivate ( ) , timeout ] ) ;
937
947
938
948
const errors : Error [ ] = [ ] ;
939
949
@@ -945,10 +955,12 @@ export function _runTaskList(
945
955
946
956
// Remove all the workers - we're shutting them down manually
947
957
const workerPromises = workers . map ( ( worker ) =>
948
- worker . release ( true ) ,
958
+ // Note force=true means that this completes immediately _except_
959
+ // it still calls the `stopWorker` async hook, so we must still
960
+ // handle a timeout.
961
+ Promise . race ( [ worker . release ( true ) , timeout ] ) ,
949
962
) ;
950
963
// Ignore the results, we're shutting down anyway
951
- // TODO: add a timeout
952
964
const [ deactivateResult , ..._ignoreWorkerReleaseResults ] =
953
965
await Promise . allSettled ( [ deactivatePromise , ...workerPromises ] ) ;
954
966
if ( deactivateResult . status === "rejected" ) {
@@ -1026,7 +1038,6 @@ export function _runTaskList(
1026
1038
} ,
1027
1039
) ;
1028
1040
1029
- // This should never call fin() since forceful shutdown always errors
1030
1041
forcefulShutdownPromise . then ( fin , finWithError ) ;
1031
1042
1032
1043
return forcefulShutdownPromise ;
0 commit comments