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: Broadcast of post to sse blocks execution #11

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

snorremd
Copy link
Owner

@snorremd snorremd commented Nov 9, 2023

It seems some issues around the Broadcast functionality was blocking my entire post db writer causing the feed to go stale as no posts were being written.

Two fixes have been implemented for this. First the Broadcast receiver function no longer requests a mutex lock. If it tries to send a post to a closed or nil channel, we don't really care. Locking for every post coming in would likely lead to situations where multiple calls to Broadcast would be waiting for the previous to complete sending channel events.

Secondly the Broadcast call is called in a go routine (i.e. go server.Broadcast(post)). This should allow the post subscriber in the serve command to quickly process the posts regardless of how long the broadcast function uses to loop over SSE clients.

Fixes #10

It seems some issues around the Broadcast functionality was blocking my
entire post db writer causing the feed to go stale as no posts were
being written.

Two fixes have been implemented for this. First the Broadcast receiver
function no longer requests a mutex lock. If it tries to send a post to
a closed or nil channel, we don't really care. Locking for every post
coming in would likely lead to situations where multiple calls to
Broadcast would be waiting for the previous to complete sending channel
events.

Secondly the Broadcast call is called in a go routine (i.e. go
server.Broadcast(post)). This should allow the post subscriber in the
serve command to quickly process the posts regardless of how long the
broadcast function uses to loop over SSE clients.
@snorremd snorremd merged commit 0a5c8eb into main Nov 9, 2023
1 check passed
@snorremd snorremd deleted the fix/broadcast-blocking branch November 9, 2023 10:48
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.

Refreshing the dashboard seems to crash the firehose subscription
1 participant