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(pubsub): handle subscription response on reconnects (#105) #107

Merged
merged 8 commits into from
Jan 25, 2024

Conversation

leruaa
Copy link
Contributor

@leruaa leruaa commented Jan 12, 2024

Motivation

Closes #105

Solution

  • Add a in-flight request for each subscription requests to be dispached on reconnect
  • Don't drop server ids to be able to update them when handling subscription responses

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

can you explain the reasoning behind this fix? i.e. why do we believe it addresses the issue?

It looks like the main difference is the Inflight added here

@leruaa
Copy link
Contributor Author

leruaa commented Jan 24, 2024

@prestwich Indeed. It seems that on reconnects, if there are no in-flight request, new subscription responses are not handled, see below:

PubSubItem::Response(resp) => match self.in_flights.handle_response(resp) {

@prestwich
Copy link
Member

I am reluctant to merge this while it contains a memory leak (even if it's not a very serious one for most people). can you test with the current code and dropping server ids?

@leruaa
Copy link
Contributor Author

leruaa commented Jan 25, 2024

@prestwich Yes I just did, see my comment above

@prestwich
Copy link
Member

prestwich commented Jan 25, 2024

ah simultaneous comments. seems the check in upsert self.local_to_server.contains_left(&local_id) should be self.local_to_sub.contains_left(&local_id) ?

@leruaa
Copy link
Contributor Author

leruaa commented Jan 25, 2024

That make sense, I will test.

@leruaa
Copy link
Contributor Author

leruaa commented Jan 25, 2024

My tests are conclusive, changing local_to_server to local_to_sub is enough to fix reconnect :). I think this PR is ready for review.

@prestwich
Copy link
Member

amazing, thanks for working in this. I will give it final review when i get to a laptop (hopefully today)

summary:

  • Missing inflight prevented correct handling of the replacement subscription response
  • incorrect condition in upsert caused overwriting the channel

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

lgtm

@prestwich prestwich merged commit 755f78c into alloy-rs:main Jan 25, 2024
14 checks passed
@leruaa leruaa deleted the fix_reconnect branch January 25, 2024 20:38
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.

[Bug] Pubsub backend reconnect doesn't work
3 participants