From 6bbc69211e92a651cbb80edbf286c7da3dd0433b Mon Sep 17 00:00:00 2001 From: "adam_cummick:g9T51EHpC9gPQqG6sb9Q@gitlab.com" Date: Thu, 21 Jan 2021 08:40:00 -0500 Subject: [PATCH] Add timeout on close Adds additional timeout wait on socket close in __exit__ Corrects for occasional duplicate ACK packet that caused a 0 len message to be read. --- adafruit_wiznet5k/adafruit_wiznet5k_socket.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py index 7b1c373..eae8c12 100644 --- a/adafruit_wiznet5k/adafruit_wiznet5k_socket.py +++ b/adafruit_wiznet5k/adafruit_wiznet5k_socket.py @@ -118,6 +118,10 @@ def __exit__(self, exc_type, exc_val, exc_tb): if time.monotonic() - stamp > 1000: raise RuntimeError("Failed to disconnect socket") self.close() + stamp = time.monotonic() + while self.status != adafruit_wiznet5k.SNSR_SOCK_CLOSED: + if time.monotonic() - stamp > 1000: + raise RuntimeError("Failed to close socket") @property def socknum(self):