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

Heartbeat loop disconnects the socket unexpectedly #219

Closed
wiredmb opened this issue Sep 7, 2018 · 5 comments · Fixed by HWiese1980/stomp.py#2
Closed

Heartbeat loop disconnects the socket unexpectedly #219

wiredmb opened this issue Sep 7, 2018 · 5 comments · Fixed by HWiese1980/stomp.py#2

Comments

@wiredmb
Copy link

wiredmb commented Sep 7, 2018

I'm using Stomp.py Version 4.1.15 and connecting the stomp consumer to Amazon MQ broker. I set heartbeat parameter to <0,30000>. Broker is sending heartbeat every 30 secs. Here is the scenario where consumer disconnects the connection:

  1. Broker sends heartbeat at X.
  2. Broker sends a message at X + 4.
  3. Heartbeat loop wakes up in the meantime, calculates difference between received_heartbeat and now which is 11 secs and sleeps for 34 secs (receive_sleep is 45 secs).
  4. Broker skips heartbeat at X + 30 (because of message sent in Error handling? #2).
  5. Heartbeat loop wakes up after 34 secs, calculates difference between received_heartbeat and now which is slightly greater than receive_sleep (in my case, 45.02 secs) and disconnects the connection with heartbeat timeout event.
  6. Also throws an exception:
on_heartbeat_timeout
Before Sleep: received_heartbeat: Fri Sep  7 16:43:41 2018, receive_sleep: 45.0, now: Fri Sep  7 16:44:27 2018
Exception in thread StompHeartbeatThread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/stomp/listener.py", line 266, in __heartbeat_loop
    sleep_time = min(next_events)
ValueError: min() arg is an empty sequence

The possible solution could be to add grace time while checking for diff_receive > self.receive_sleep in heartbeat loop. Please suggest.

@wiredmb wiredmb changed the title Setting only receiving heartbeat disconnects the connection Heartbeat loop disconnects the socket Sep 7, 2018
@wiredmb wiredmb changed the title Heartbeat loop disconnects the socket Heartbeat loop disconnects the socket unexpectedly Sep 7, 2018
@emakarov
Copy link

emakarov commented Jan 4, 2019

hi @wiredmb
did you manage to resolve this issue?
and why your broker has sent the event 2? (Broker sends a message at X + 4.)

@jasonrbriggs
Copy link
Owner

Believe this is resolved in the latest version.

@HWiese1980
Copy link
Contributor

It is not. We're experiencing this issue right now. We're on stomp.py v7.0.0.

@HWiese1980
Copy link
Contributor

HWiese1980 commented Nov 24, 2021

Cause is that next_events is empty. It is empty because self.next_outbound_heartbeat is None. Furthermore, self.received_heartbeat + self.receive_sleep - now is <= 0.0 so that eventually there's nothing added to next_events.

Source: stomp/listener.py:271 and following lines

@HWiese1980
Copy link
Contributor

@jasonrbriggs Have you seen this one? The error persists and it's a behavior I see quite often.

I'll make a small change and send you a pull request for review that should fix this particular problem. I'm not sure if it has some implications or impacts downstream as I'm not that deep in your code yet.

HWiese1980 added a commit to HWiese1980/stomp.py that referenced this issue Dec 2, 2021
If there aren't any items in `next_events`, `min(next_events)` fails with a `ValueError`

Tries to fix: jasonrbriggs#219
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 a pull request may close this issue.

4 participants