Skip to content
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

Fix setTimeout ID collisions. #2110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jp4a50
Copy link
Collaborator

@jp4a50 jp4a50 commented May 10, 2024

workerd::api::gpu::AsyncRunner was using a different instance of TimeoutId::Generator than is used for setTimeout calls from JS.

I fix this by moving ownership of the TimeoutIdGenerator into the TimeoutManagerImpl itself.

In the case of gpu::AsyncRunner, it doesn't look like there's any need to generate an ID for the timeout, so we could alternatively approach this by re-using the timeout logic but not generating an ID in order to avoid silently using up timeout ID values under the hood. Not sure whether it's worth it.

@jp4a50 jp4a50 requested review from a team as code owners May 10, 2024 20:10
@jp4a50
Copy link
Collaborator Author

jp4a50 commented May 10, 2024

Hmm, actually, this does change the semantics of setTimeout/clearTimeout across multiple requests that execute within the same global scope.

Currently, I think it would be possible to clear a timeout set by a previous request.

Is this something which we would want to continue to support, or are we OK just preventing this? @jasnell

Copy link
Member

@kentonv kentonv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally designed so that IDs returned by setTimeout() are unique across the isolate, not just a single request. Note that the design doesn't allow one request to clear another request's timeouts, it only ensures non-overlapping IDs. This could be important if someone stored IDs in a global map or something -- not sure why someone would want to do that, but it's possible.

So, I don't think we should make this change as-is. Instead, the GPU API should probably use the timeout ID generator from the global scope object.

Incidentally, I don't think the GPU API could be causing the ID conflicts we've seen in production, since this API isn't currently available in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants