Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Change delivery of websocket for hibernation event #675

Merged
merged 1 commit into from
May 22, 2023

Conversation

MellowYarker
Copy link
Contributor

We noticed the webSocketForEventHandler reference was being overwritten by subsequent events before an event that set it could read the value.

To fix this, we use a map of IDs to HibernatableWebSockets and pass the ID to the event itself so it can find its associated websocket.

kj::Maybe<HibernatableWebSocket&> webSocketForEventHandler;
// Allows the HibernatableWebSocket event handler that is currently running to access the
// HibernatableWebSocket that it needs to execute.
const uint16_t EVENT_QUEUE_CAPACITY = 1024;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what a good value for this is, the previous assumption of 1 was too low, I feel like 1024 is pretty high but it I can imagine scenario's where we could go higher (you have 32k websockets that all message/close/whatever at once). It really depends on the latency between calling customEvent() and then actually running it.

src/workerd/io/hibernation-manager.h Outdated Show resolved Hide resolved
src/workerd/api/hibernatable-web-socket.c++ Outdated Show resolved Hide resolved
src/workerd/api/hibernatable-web-socket.h Outdated Show resolved Hide resolved
@MellowYarker MellowYarker force-pushed the milan/hibernation-deliver-ws branch 2 times, most recently from d2d285c to a31bb99 Compare May 22, 2023 20:34
We noticed the `webSocketForEventHandler` reference was being
overwritten by subsequent events before an event that set it could read
the value.

To fix this, we use a map of `ID`s to `HibernatableWebSocket`s and pass
the ID to the event itself so it can find its associated websocket.
@MellowYarker
Copy link
Contributor Author

MellowYarker commented May 22, 2023

Got nervous about potential lifetime issues so StringPtr -> String in some places + removing outdated includes/comments c6ed1aa

@MellowYarker MellowYarker force-pushed the milan/hibernation-deliver-ws branch from c6ed1aa to 87ee94f Compare May 22, 2023 20:56
@MellowYarker MellowYarker merged commit 0fab318 into main May 22, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants