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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Drop messages rather than block
Signed-off-by: Spike Curtis <spike@coder.com>
  • Loading branch information
spikecurtis committed May 4, 2023
commit e9dd9088b9441f71387e9eae47da5fc3cabf42cc
11 changes: 9 additions & 2 deletions coderd/database/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type pgPubsub struct {
}

// messageBufferSize is the maximum number of unhandled messages we will buffer
// for a subscriber before blocking the pgPubsub.
// for a subscriber before dropping messages.
const messageBufferSize = 2048

// Subscribe calls the listener when an event matching the name is received.
Expand Down Expand Up @@ -124,7 +124,14 @@ func (p *pgPubsub) listenReceive(notif *pq.Notification) {
}
extra := []byte(notif.Extra)
for _, listener := range listeners {
listener <- extra
select {
case listener <- extra:
// ok!
default:
// bad news, we dropped the event because the listener isn't
// keeping up
// TODO (spike): figure out a way to communicate this to the Listener
}
}
}

Expand Down