-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
worker: prevent event loop starvation through MessagePorts #28030
worker: prevent event loop starvation through MessagePorts #28030
Conversation
Limit the number of messages processed without interruption on a given `MessagePort` to prevent event loop starvation. This aligns the behaviour better with the web.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: is it from a case in WPT?
|
@addaleax cool, do you have an order to go through the tests? We talked about auditing the WPT and port as much as possible before moving workers out of experimental, so some kind of checklist might be helpful to track the progress. (I can probably script some checklist using node-core-utils, if you like) |
} | ||
|
||
port2.postMessage(0); | ||
assert(count++ < 10000, `hit ${count} loop iterations`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be useful to document that this depends on the constant in the source - in case someone wants to turn it down later. Or we could also export the constant and do some math here..
(Non-blocking BTW)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I don't think a named constant is necessary, it's pretty obvious what it does.
I’ve gone through all the files in the order in which my editor opened them, and opened PRs along the way 🙂 There’s one left, and it may require a (slightly?) different approach here, because the current queue of messages should still end up being processed even if one of the message handlers closes the port; and this PR would break that, because after closing the port, |
Limit the number of messages processed without interruption on a given `MessagePort` to prevent event loop starvation, but still make sure that all messages are emitted that were already in the queue when emitting began. This aligns the behaviour better with the web. Refs: nodejs#28030
Limit the number of messages processed without interruption on a given `MessagePort` to prevent event loop starvation, but still make sure that all messages are emitted that were already in the queue when emitting began. This aligns the behaviour better with the web. Refs: nodejs#28030
Limit the number of messages processed without interruption on a given `MessagePort` to prevent event loop starvation, but still make sure that all messages are emitted that were already in the queue when emitting began. This aligns the behaviour better with the web. Refs: #28030 PR-URL: #29315 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Limit the number of messages processed without interruption on a given `MessagePort` to prevent event loop starvation, but still make sure that all messages are emitted that were already in the queue when emitting began. This aligns the behaviour better with the web. Refs: #28030 PR-URL: #29315 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Limit the number of messages processed without interruption on a given `MessagePort` to prevent event loop starvation, but still make sure that all messages are emitted that were already in the queue when emitting began. This aligns the behaviour better with the web. Refs: #28030 PR-URL: #29315 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Limit the number of messages processed without interruption on a
given
MessagePort
to prevent event loop starvation.This aligns the behaviour better with the web.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes