File tree 2 files changed +8
-0
lines changed
2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import {fileURLToPath} from 'url';
3
3
import { Worker } from 'worker_threads' ;
4
4
5
5
import Emittery from 'emittery' ;
6
+ import pEvent from 'p-event' ;
6
7
7
8
import { controlFlow } from './ipc-flow-control.cjs' ;
8
9
@@ -31,8 +32,14 @@ const createWorker = (options, execArgv) => {
31
32
stderr : true
32
33
} ) ;
33
34
postMessage = worker . postMessage . bind ( worker ) ;
35
+
36
+ // Ensure we've seen this event before we terminate the worker thread, as a
37
+ // workaround for https://github.com/nodejs/node/issues/38418.
38
+ const starting = pEvent ( worker , 'message' , ( { ava} ) => ava && ava . type === 'starting' ) ;
39
+
34
40
close = async ( ) => {
35
41
try {
42
+ await starting ;
36
43
await worker . terminate ( ) ;
37
44
} finally {
38
45
// No-op
Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ const onError = error => {
222
222
} ;
223
223
224
224
if ( isRunningInThread ) {
225
+ channel . send ( { type : 'starting' } ) ; // AVA won't terminate the worker thread until it's seen this message.
225
226
const { options} = workerData ;
226
227
delete workerData . options ; // Don't allow user code access.
227
228
run ( options ) . catch ( onError ) ; // eslint-disable-line promise/prefer-await-to-then
You can’t perform that action at this time.
0 commit comments