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

Unsubscribe timeout to prevent deadlock (#1) #133

Merged
merged 1 commit into from
Mar 2, 2024
Merged

Conversation

maelick
Copy link

@maelick maelick commented Feb 28, 2024

While using this lib to write a simulator for performance testing, I found out that the library deadlocks if the stomp server does not respond during unsubscribe (e.g. too high load).

The following branch has a test to reproduce the deadlock without the fix applied: https://github.com/maelick/go-stomp/tree/reproduce-unsubscribe-deadlock

This PR is similar to #126 and add a timeout to Unsubscribe to prevent deadlock when the server does not respond/send a receipt.

More specifically it:

  • adds unsubscribe unit tests to reproduce deadlock
  • waits with timeout in Subscription.Unsubscribe => sends an error frame if timeout occurs
  • adds a new error for unsubscribe timeout
  • adds a new ConnOpt for unsubscribe timeout

The changes are covered with unit tests and I also ensured that my simulator does not deadlock anymore when the server is under high load.

Add a timeout to Unsubscribe to prevent deadlock when server does not respond/send receipt

* add unsubscribe unit tests to reproduce deadlock
* Wait with timeout in Subscription.Unsubscribe => sends an error frame if timeout occurs
* Add new error for unsubscribe timeout
* Add ConnOpt for unsubscribe timeout
@@ -80,7 +83,12 @@ func (s *Subscription) Unsubscribe(opts ...func(*frame.Frame) error) error {
f.Header.Set(ReplyToHeader, s.id)
}

s.conn.sendFrame(f)
err := s.conn.sendFrame(f)
if errors.Is(err, ErrClosedUnexpectedly) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@worg worg merged commit 5179ed7 into go-stomp:master Mar 2, 2024
2 checks passed
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.

2 participants