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

WebSocket Hibernation Manager #449

Merged
merged 4 commits into from
May 9, 2023
Merged

Conversation

MellowYarker
Copy link
Contributor

Old PR: #339

@jqmmes, @xortive

@MellowYarker
Copy link
Contributor Author

@jqmmes I got rid of the doubly linked list I was adding to KJ here:

So assuming there aren't linking issues with std::list you should be able to use my branch now.

// Also note that we box the keys and values such that in the event of a hashmap resizing we don't
// move the underlying data (thereby keeping any references intact).

std::list<kj::Own<HibernatableWebSocket>> allWs;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worth thinking about Harris's comment here capnproto/capnproto#1639 (comment), since HibernatableWebSocket::activeWebSocket would be in the Accepted state if it were nonnull and that has a noexcept(false) dtor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just happened to notice this comment, you can probably get away with invoking clear() on this list in the noexcept(false) dtor. Keep in mind that you run the risk of throwing from multiple elements of the container, which will probably terminate the program: https://en.cppreference.com/w/cpp/language/throw#Stack_unwinding.

@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 3 times, most recently from 9d80560 to 9b6c104 Compare March 22, 2023 21:59
// We need to get a HibernationManager to give the websocket to.
auto& a = KJ_REQUIRE_NONNULL(IoContext::current().getActor());
if (a.getHibernationManager() == nullptr) {
// TODO(now): Actually set the hibernation manager.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI this TODO(now) is replaced in a later commit once we actually have a HibernationManagerImpl.

@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 5 times, most recently from 6b1deb1 to 48b0ba4 Compare March 29, 2023 15:50
@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 4 times, most recently from 1eb4245 to c06e9bb Compare March 30, 2023 20:54
@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 4 times, most recently from 6465e89 to c142f36 Compare April 3, 2023 15:21
@MellowYarker
Copy link
Contributor Author

610eda0
1d952cb

Talked with the team; we're going to serialize the attachment every time the setter is called so we can send a useful error to the user if it's too large. One idea that came up was introducing a getter/setter on the websocket object, since it feels weird to throw when assigning to a property (i.e., provide ws.setAttachment(obj)). @jasnell do you have any thoughts on this?

@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 5 times, most recently from 5c25f68 to 91070fa Compare May 3, 2023 21:35
@MellowYarker
Copy link
Contributor Author

Rebased on main + bumped connection limit back up because tests are passing with the lower limit.

@MellowYarker
Copy link
Contributor Author

5278b5e
c866fab

Changed the api for the attachment, surprisingly turned out simpler than it was before

@MellowYarker
Copy link
Contributor Author

@xortive I removed some of the TODO(now)s, anything left over is better left as a hint for review. Also made the ownership transfer of websocket properties more expicit by reusing the HibernationPackage when re-creating the api::WebSocket.

Copy link
Collaborator

@xortive xortive left a comment

Choose a reason for hiding this comment

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

I think this is ready to approve after these last batch of fixes

src/workerd/api/web-socket.c++ Outdated Show resolved Hide resolved
src/workerd/api/hibernatable-web-socket.c++ Outdated Show resolved Hide resolved
src/workerd/api/hibernatable-web-socket.c++ 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
src/workerd/api/hibernatable-web-socket.c++ Outdated Show resolved Hide resolved
src/workerd/io/hibernation-manager.c++ Outdated Show resolved Hide resolved
src/workerd/io/hibernation-manager.c++ Outdated Show resolved Hide resolved
@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 2 times, most recently from 518becd to 5c724e2 Compare May 8, 2023 21:59
@MellowYarker
Copy link
Contributor Author

Must've lost this include in the rebase somehow? ba1b098

@MellowYarker MellowYarker force-pushed the milan/hibernation-manager branch 2 times, most recently from 0c50dd8 to f02b98a Compare May 8, 2023 23:05
We want to use the existing structure of api::WebSocket for hibernatable
websocket's, but the hibernation manager needs to own the kj::WebSocket.
Currently, the api::WebSocket owns it, so we need to move a couple
things around.
Also modifying the way we pass errors to the hibernation error event
because previous assumptions (rpc related) are no longer true.
Previously we introduced the HibernationManager class, but this commit
actually implements it. The HibernationManager needs to be stored
somewhere that lives long, so we'll put it in the deferred proxy task.
@MellowYarker
Copy link
Contributor Author

Rebased to get rid of conflicts.

@MellowYarker MellowYarker merged commit 811f584 into main May 9, 2023
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.

5 participants