threads.js icon indicating copy to clipboard operation
threads.js copied to clipboard

Cannot terminate pool when there is an init timeout

Open kellyselden opened this issue 4 years ago • 1 comments

I'm testing my error handling code. I forced a timeout of 100ms in spawn, which causes the expected error. Inside the try/finally, I call .terminate(true). With the debugger paused on the line that calls terminate, I see:

Screenshot 2021-09-16 at 17 54 48

which is expected. Then I let the program complete, and I'm left with a hung debugger and the workers still alive:

Screenshot 2021-09-16 at 17 55 03

I should note that this terminate logic works normally if the error is not an init timeout.

What are your thoughts on this?

kellyselden avatar Sep 17 '21 00:09 kellyselden

Sorry, just saw that I didn't reply yet.

I am a bit puzzled regarding this statement:

I forced a timeout of 100ms in spawn, which causes the expected error. Inside the try/finally, I call .terminate(true).

I imagine your code looks something like this:

try {
  const thread = await spawn(new Worker("./path/to/worker"))
  // …
} finally {
  thread.terminate()    // <--- ?!
}

Obviously, you cannot terminate a thread that is potentially not even initialized yet (if async spawn() call has not completed), so your code must look different. Can you shine some light on that?

andywer avatar Oct 07 '21 16:10 andywer