Skip to content

fix: pubsub ordering #7404

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

Merged
merged 2 commits into from
May 5, 2023
Merged

fix: pubsub ordering #7404

merged 2 commits into from
May 5, 2023

Conversation

spikecurtis
Copy link
Contributor

This PR fixes the pubsub so that it calls back messages in order.

This is important for applications that depend on message order (as opposed to just using the pubsub as a kick to go load updates).

In particular, the streaming provisioner job logs endpoint is very complicated and still broken (c.f. #7371) trying to deal with out of order messages.

As a second example, the haCoordinator will fail even the most trivial example of a client or agent sending multiple node updates if the pubsub messages get reordered.

This PR creates an in-order queue of messages per subscriber (just a fixed size chan) and runs a goroutine per subscriber (instead of per subscriber per message) to deliver them.

If the queue gets backed up, we drop messages rather than block. This was chosen rather than blocking the whole pubsub for a single Listener that isn't keeping up. Since the pg.Listener is, under the covers, handling DB reconnects, the pubsub can already drop messages, so from a design standpoint it's nothing new. In another PR I plan to add the capability for subscribers to get notified if messages are dropped.

Signed-off-by: Spike Curtis <spike@coder.com>
Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtis spikecurtis merged commit a6a4489 into main May 5, 2023
@spikecurtis spikecurtis deleted the spike/pubsub-ordering branch May 5, 2023 05:39
@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants