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

Event triggered on Connection State Recovery Expiration #5250

Open
bryghtlabs-richard opened this issue Dec 4, 2024 · 2 comments
Open

Event triggered on Connection State Recovery Expiration #5250

bryghtlabs-richard opened this issue Dec 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@bryghtlabs-richard
Copy link

Is your feature request related to a problem? Please describe.

Per-connection, we're keeping a large object in memory, which we would prefer to use across connections that are recovered through connection-state-recovery. Connection state recovery solves one problem for us, in that we can reconnect a client to its object, but this makes it harder to know when to delete the object.

Describe the solution you'd like

When a connection exceeds the connection state recovery maxDisconnectionDuration, I'd like an event trigger with the SocketID as an argument.

Describe alternatives you've considered

We've considered setting an additional timeout, but this won't ever be as accurate - we'd have to make this timeout longer than maxDisconnectionDuration, and deal with our large staying around longer than needed.

@bryghtlabs-richard bryghtlabs-richard added the enhancement New feature or request label Dec 4, 2024
@darrachequesne
Copy link
Member

Hi! That's an interesting idea 👍

I think implementing this for the in-memory adapter would be quite straightforward.

For the adapter based on Redis streams, we would need to listen to the "expired" events (ref), though it would not be reliable if the Redis client disconnects.

Not sure how we could implement it for the adapter based on MongoDB though...

Regarding the API, would something like this suit your needs?

io.of("/").adapter.on("sessionExpiry", (sid) => {
  // ...
});

@bryghtlabs-richard
Copy link
Author

Regarding the API, I must confess I'm quite new to JS, but it looks good to me. We'd use that handler to destroy the corresponding large object paired to sid.

One question - with the in-memory adapter, without connection-state-recovery, would this event still be received?

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

No branches or pull requests

2 participants