Skip to content

Commit 493b6ec

Browse files
brefrabouwew
authored andcommitted
Do not call resend within locking context
1 parent 6b330e9 commit 493b6ec

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

plugwise/controller.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def message_handler(self, message):
290290

291291
def _post_message_action(self, seq_id, ack_response=None, request="unknown"):
292292
"""Execute action if request has been successful."""
293+
resend_request = False
293294
with self.lock_expected_responses:
294295
if seq_id in self.expected_responses:
295296
if ack_response in (*REQUEST_SUCCESS, None):
@@ -311,7 +312,7 @@ def _post_message_action(self, seq_id, ack_response=None, request="unknown"):
311312
)
312313
del self.expected_responses[seq_id]
313314
elif ack_response in REQUEST_FAILED:
314-
self.resend(seq_id)
315+
resend_request = True
315316
else:
316317
if not self.last_seq_id:
317318
if b"0000" in self.expected_responses:
@@ -327,10 +328,13 @@ def _post_message_action(self, seq_id, ack_response=None, request="unknown"):
327328
request,
328329
str(seq_id),
329330
)
331+
if resend_request:
332+
self.resend(seq_id)
330333

331334
def _receive_timeout_loop(self):
332335
"""Daemon to time out open requests without any (n)ack response message."""
333336
while self._receive_timeout_thread_state:
337+
resend_list = []
334338
with self.lock_expected_responses:
335339
for seq_id in list(self.expected_responses.keys()):
336340
if self.expected_responses[seq_id][3] is not None:
@@ -347,7 +351,9 @@ def _receive_timeout_loop(self):
347351
_mac,
348352
str(seq_id),
349353
)
350-
self.resend(seq_id)
354+
resend_list.append(seq_id)
355+
for seq_id in resend_list:
356+
self.resend(seq_id)
351357
receive_timeout_checker = 0
352358
while (
353359
receive_timeout_checker < MESSAGE_TIME_OUT

0 commit comments

Comments
 (0)