-
Notifications
You must be signed in to change notification settings - Fork 0
Ensure we've acquired the worker lock before passing it to the worker. #36
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
Conversation
Summary of ChangesHello @pkaminski, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical race condition in the worker connection process where a web worker could incorrectly perceive the client as unresponsive and terminate its connection prematurely. By introducing an explicit Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request correctly addresses a critical race condition by ensuring the client acquires the worker lock before initializing the bridge. The change to use async/await in connectWorker also improves code readability. The addition of extra context to crash reports is a good enhancement for debugging. I have one suggestion to make the new lock-waiting logic slightly more concise. The version bump is appropriate for this fix.
src/Truss.js
Outdated
| let resolveLockReady; | ||
| const lockReady = new Promise(resolve => {resolveLockReady = resolve;}); | ||
| navigator.locks.request(webWorker.lockName, () => { | ||
| resolveLockReady(); | ||
| // eslint-disable-next-line lodash/prefer-noop | ||
| return new Promise(() => {/* release lock only on page exit or crash */}); | ||
| }); | ||
| await lockReady; |
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.
While the current implementation correctly waits for the lock, the logic for creating and awaiting the lockReady promise can be simplified. You can wrap the navigator.locks.request call in a single new Promise and await that directly. This avoids the need for the separate resolveLockReady variable, making the code a bit more self-contained and easier to read.
| let resolveLockReady; | |
| const lockReady = new Promise(resolve => {resolveLockReady = resolve;}); | |
| navigator.locks.request(webWorker.lockName, () => { | |
| resolveLockReady(); | |
| // eslint-disable-next-line lodash/prefer-noop | |
| return new Promise(() => {/* release lock only on page exit or crash */}); | |
| }); | |
| await lockReady; | |
| await new Promise(resolve => { | |
| navigator.locks.request(webWorker.lockName, () => { | |
| resolve(); | |
| // eslint-disable-next-line lodash/prefer-noop | |
| return new Promise(() => {/* release lock only on page exit or crash */}); | |
| }); | |
| }); |
Otherwise, the worker might believe that the client is dead on arrival and destroy the connection immediately.
pkaminski
left a comment
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.
@pkaminski resolved 1 discussion.
Reviewable status: 0 of 8 files reviewed, all discussions resolved (waiting on @snoack).
snoack
left a comment
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.
@snoack reviewed 8 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @pkaminski).
src/Truss.js line 252 at r2 (raw file):
resolve(); // eslint-disable-next-line lodash/prefer-noop return new Promise(() => {/* release lock only on page exit or crash */});
I suppose we could use _.noop here though.
pkaminski
left a comment
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.
@pkaminski made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @snoack).
src/Truss.js line 252 at r2 (raw file):
Previously, snoack (Sebastian Noack) wrote…
I suppose we could use
_.noophere though.
We could, but I liked the explicit comment on why we're using an unresolvable promise.
pkaminski
left a comment
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.
@pkaminski resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @pkaminski).
Otherwise, the worker might believe that the client is dead on arrival and destroy the connection immediately.
This change is