Skip to content

Commit

Permalink
Merge pull request #1010 from vitaly-krugl/issue708-unwanted-graceful…
Browse files Browse the repository at this point in the history
…-close-on-heartbeat-timeout

Don't attempt graceful AMQP Connection.Close upon heartbeat timeout
  • Loading branch information
lukebakken committed Apr 10, 2018
2 parents aebcd1a + 85946cf commit 0793350
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 7 additions & 9 deletions pika/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def send_and_check(self):
self._heartbeat_frames_sent)

if self.connection_is_idle:
return self._close_connection()
self._close_connection()
return

# Connection has not received any data, increment the counter
if not self._has_received_data:
Expand Down Expand Up @@ -116,13 +117,9 @@ def _close_connection(self):
duration = self._max_idle_count * self._interval
text = HeartbeatChecker._STALE_CONNECTION % duration

# NOTE: this won't achieve the perceived effect of sending
# Connection.Close to broker, because the frame will only get buffered
# in memory before the next statement terminates the connection.
self._connection.close(HeartbeatChecker._CONNECTION_FORCED, text)

self._connection._on_terminate(HeartbeatChecker._CONNECTION_FORCED,
text)
self._connection._on_terminate( # pylint: disable=W0212
HeartbeatChecker._CONNECTION_FORCED,
text)

@property
def _has_received_data(self):
Expand All @@ -147,7 +144,8 @@ def _send_heartbeat_frame(self):
"""
LOGGER.debug('Sending heartbeat frame')
self._connection._send_frame(self._new_heartbeat_frame())
self._connection._send_frame( # pylint: disable=W0212
self._new_heartbeat_frame())
self._heartbeat_frames_sent += 1

def _setup_timer(self):
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/heartbeat_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ def test_connection_close(self):
self.obj._close_connection()
reason = self.obj._STALE_CONNECTION % (
self.obj._max_idle_count * self.obj._interval)
self.mock_conn.close.assert_called_once_with(
self.obj._CONNECTION_FORCED, reason)
self.mock_conn._on_terminate.assert_called_once_with(
self.obj._CONNECTION_FORCED, reason)

Expand Down

0 comments on commit 0793350

Please sign in to comment.