loaders
loaders copied to clipboard
What will happen if the loader thread terminates due to an error?
When loaders are moved off the main thread, what will happen if the loader thread crashes / terminates? Could be due to an uncaught error, code erroneously calling process.exit()
, or any other reason I didn't think of.
Supposing the main thread makes a blocking / synchronous request to the loader thread using postMessage
and Atomics.wait
. We need to guard against hanging the main thread indefinitely in the event the loader thread crashes. The motivation is running a compiler in the loader thread and also querying the same compiler within synchronous require()
hooks on the main thread.
In past threading work, I've done this with a watchdog thread and a worker thread, where the watchdog checks for the worker to terminate and wakes up the main thread, preventing the main thread from hanging.
If loaders are spec-ed such that any termination of the loader thread is guaranteed to crash the node process, then this watchdog may not be needed. However, if "crash the node process" means waiting for the main thread to respond to a process.on('unhandledException')
or something like that, then we've still got the problem of a hanging main thread.
If loaders are spec-ed such that any termination of the loader thread is guaranteed to crash the node process
Yes, I would imagine node should crash. Perhaps @bmeck has more insight though?
This is now live. The answer is: it crashes.