From 1063a01ee4b1ba6a4f301d984355626990643eac Mon Sep 17 00:00:00 2001 From: foxy82 Date: Mon, 3 Apr 2023 12:10:28 +0100 Subject: [PATCH 1/3] Fix infinite loop when requesting too quickly On the Pico W we can get in an infinite loop if we request pages too quickly. This is because we get an OSError 32 Broken Pipe back from which we can't recover. I've made it so any of the unexpected errors will be re-raised. Fixes this issue: https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer/issues/44 --- adafruit_httpserver/response.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_httpserver/response.py b/adafruit_httpserver/response.py index c6cdcea..acbd4bb 100644 --- a/adafruit_httpserver/response.py +++ b/adafruit_httpserver/response.py @@ -245,5 +245,7 @@ def _send_bytes( except OSError as exc: if exc.errno == EAGAIN: continue - if exc.errno == ECONNRESET: + elif exc.errno == ECONNRESET: return + else: + raise exc From fc07ed4befa70a0bec3463cb6b02f13059f3cdac Mon Sep 17 00:00:00 2001 From: foxy82 Date: Mon, 3 Apr 2023 12:27:54 +0100 Subject: [PATCH 2/3] Update response.py Fix linting issue --- adafruit_httpserver/response.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_httpserver/response.py b/adafruit_httpserver/response.py index acbd4bb..c24a14f 100644 --- a/adafruit_httpserver/response.py +++ b/adafruit_httpserver/response.py @@ -245,7 +245,6 @@ def _send_bytes( except OSError as exc: if exc.errno == EAGAIN: continue - elif exc.errno == ECONNRESET: + if exc.errno == ECONNRESET: return - else: - raise exc + raise From 1649a457001b49d17fe90f6a8676fd759eb436d6 Mon Sep 17 00:00:00 2001 From: foxy82 Date: Mon, 3 Apr 2023 12:31:00 +0100 Subject: [PATCH 3/3] Update server.py Ensure unexpected OSError isn't swallowed. --- adafruit_httpserver/server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_httpserver/server.py b/adafruit_httpserver/server.py index 0a41616..8ee473b 100644 --- a/adafruit_httpserver/server.py +++ b/adafruit_httpserver/server.py @@ -104,6 +104,7 @@ def _receive_header_bytes( except OSError as ex: if ex.errno == ETIMEDOUT: break + raise except Exception as ex: raise ex return received_bytes @@ -122,6 +123,7 @@ def _receive_body_bytes( except OSError as ex: if ex.errno == ETIMEDOUT: break + raise except Exception as ex: raise ex return received_body_bytes[:content_length]