worker: use special message as MessagePort close command
(The first commit is cleanup from https://github.com/nodejs/node/pull/27294, with which this is going to have conflicts anyway…)
When a MessagePort
connected to another MessagePort
closes, the
latter MessagePort
will be closed as well. Until now, this is done
by testing whether the ports are still entangled after processing
messages. This leaves open a race condition window in which messages
sent just before the closure can be lost when timing is unfortunate.
(A description of the timing is in the test file.)
This can be addressed by using a special message instead, which is
the last message received by a MessagePort
. This way, all previously
sent messages are processed first.
Fixes: https://github.com/nodejs/node/issues/22762
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines