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 deadlock on notifications #242

Merged
merged 2 commits into from
Oct 7, 2021
Merged

Fix deadlock on notifications #242

merged 2 commits into from
Oct 7, 2021

Conversation

hannahhoward
Copy link
Collaborator

Goals

The notification queue is extremely vulnerable to deadlocks if one of the subscribers takes a long time to process a notification.

Implementation

This change makes calls to Subscribe and Publish more non-blocking by treating internal commands as an unbuffered queue, rather than a blocking channel. We use a mutex and a sync.Cond to implement, a fairly standard way to implement a non-blocking concurrent queue.

We also cleanup the subscriber for the response manager. (this was a side effect of initially trying to solve the deadlock issue by making the subscriber more non-blocking in it's processing). Ultimately, it may make sense to move these subscribers directly into the message queue and remove the notification system entirely. but in the meantime, it makes sense for subscriber not to have access to private vars in the response manager

The notification queue is extremely vulnerable to deadlocks if one of
the subscribers takes a long time to process a notification. This change
makes calls to Subscribe and Publish more non-blocking by treating
internal commands as an unbuffered queue, rather than a blocking
channel.

We also cleanup the subscriber for the response manager. Ultimately, it
may make sense to move these subscribers directly into the message queue
and remove the notification system entirely. but in the meantime, it
makes sense for subscriber not to have access to private vars in the
repsonse manager
@willscott
Copy link
Collaborator

should we log/warn/etc if the length of the cmds gets really big? it still seems like we'll end up at some point wanting an ability to do some sort of back-pressure, right?

@hannahhoward
Copy link
Collaborator Author

maybe worth a log message -- I agree. Though I don't believe this will ever get HUGE... I could be totally wrong... I dunno I think I'd prefer to make a debug message for now.

@hannahhoward hannahhoward merged commit 49f490d into main Oct 7, 2021
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
@mvdan mvdan deleted the fix/subscriber-deadlock branch December 15, 2021 14:18
marten-seemann pushed a commit that referenced this pull request Mar 2, 2023
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.

3 participants