Skip to content

Commit a8bf19f

Browse files
authored
Honor reconnect_backoff in conn.connect() (#1342)
* Honor reconnect_backoff in conn.connect()
1 parent da65a56 commit a8bf19f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

kafka/conn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _next_afi_host_port(self):
278278

279279
def connect(self):
280280
"""Attempt to connect and return ConnectionState"""
281-
if self.state is ConnectionStates.DISCONNECTED:
281+
if self.state is ConnectionStates.DISCONNECTED and not self.blacked_out():
282282
self.last_attempt = time.time()
283283
next_lookup = self._next_afi_host_port()
284284
if not next_lookup:

test/test_conn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def test_lookup_on_connect():
263263
]
264264

265265
with mock.patch("socket.getaddrinfo", return_value=mock_return2) as m:
266+
conn.last_attempt = 0
266267
conn.connect()
267268
m.assert_called_once_with(hostname, port, 0, 1)
268269
conn.close()
@@ -288,6 +289,7 @@ def test_relookup_on_failure():
288289
]
289290

290291
with mock.patch("socket.getaddrinfo", return_value=mock_return2) as m:
292+
conn.last_attempt = 0
291293
conn.connect()
292294
m.assert_called_once_with(hostname, port, 0, 1)
293295
conn.close()

0 commit comments

Comments
 (0)