Skip to content

fix(rivetkit): unsubscribe on the server when a once() listener fires - #5811

Open
Abhishek-B-R wants to merge 1 commit into
rivet-dev:mainfrom
Abhishek-B-R:fix/conn-once-unsubscribe
Open

Abhishek-B-R wants to merge 1 commit into
rivet-dev:mainfrom
Abhishek-B-R:fix/conn-once-unsubscribe

Conversation

@Abhishek-B-R

Copy link
Copy Markdown

Description

  • when a once() listener fired and it was the last listener, the client dropped it locally but never told the actor, so the actor kept sending that event until the next reconnect
  • the same cleanup could also delete a listener that was added during dispatch (unsubscribe then subscribe again inside the callback), so the new listener never fired
  • the cleanup now only runs if the map still holds that listener set, and it sends the unsubscribe like the manual unsubscribe path does
  • added unit tests with a fake socket for all three cases

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • npx vitest run tests/actor-conn-subscriptions.test.ts in rivetkit-typescript/packages/rivetkit: 3/3. on main the once() unsubscribe test and the resubscribe during dispatch test fail, the once() next to on() test passes on both
  • the tests use a hand written fake driver and websocket, no vi.mock
  • npx vitest run --exclude 'tests/driver/**': same result as main plus the new tests. the files that fail to load on main need the native napi build, which i don't have locally
  • biome check clean on the new test file

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@the-company-company the-company-company Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues found

Reviewed commit d003d37.

@Abhishek-B-R

Copy link
Copy Markdown
Author

@eersnington friendly bump: this fixes once() listeners not unsubscribing on the actor (plus the resubscribe-during-dispatch case), with unit tests for all three paths. It merges cleanly with main; the CI workflows are waiting on maintainer approval to run. Happy to adjust anything if the approach doesn't fit.

@Abhishek-B-R

Copy link
Copy Markdown
Author

@NathanFlurry friendly bump: this makes the client send the unsubscribe to the actor when the last once() listener fires, and stops that cleanup from deleting a listener re-added during dispatch, with unit tests for all three cases. It's a single commit with no conflicts against main. Happy to adjust anything if the approach doesn't fit.

This branch has not been deployed

No deployments
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.

1 participant