From 20b0e021a3a3b2ac5ed3879925d24bd349376a82 Mon Sep 17 00:00:00 2001 From: Sadat Tarique Date: Tue, 16 Jun 2026 16:38:03 -0400 Subject: [PATCH 1/2] Catch OSError when persisting heartbeat to queue Prevents a crash when the disk is full by catching OSError in add_request() and logging a warning instead of letting it propagate. Fixes #8 --- aw_client/client.py | 7 +++++-- tests/test_requestqueue.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/aw_client/client.py b/aw_client/client.py index 4e454be..13eabfd 100644 --- a/aw_client/client.py +++ b/aw_client/client.py @@ -551,7 +551,10 @@ def add_request(self, endpoint: str, data: dict) -> None: """ assert "/heartbeat" in endpoint assert isinstance(data, dict) - self._persistqueue.put(QueuedRequest(endpoint, data)) + try: + self._persistqueue.put(QueuedRequest(endpoint, data)) + except OSError as e: + logger.warning(f"Failed to queue request, possibly due to insufficient disk space: {e}") def register_bucket(self, bucket_id: str, event_type: str) -> None: - self._registered_buckets.append(Bucket(bucket_id, event_type)) + self._registered_buckets.append(Bucket(bucket_id, event_type)) \ No newline at end of file diff --git a/tests/test_requestqueue.py b/tests/test_requestqueue.py index 0e28fff..117e61a 100644 --- a/tests/test_requestqueue.py +++ b/tests/test_requestqueue.py @@ -60,3 +60,16 @@ def test_complex(): sleep(1) rq.stop() rq.join() + +def test_add_request_disk_full(): + """Ensures that add_request doesn't crash if the queue can't be written to disk""" + client = MockClient() + rq = RequestQueue(client) # type: ignore + + def raise_oserror(*args, **kwargs): + raise OSError("No space left on device") + + rq._persistqueue.put = raise_oserror # type: ignore + + # Should not raise, the OSError should be caught internally and logged instead + rq.add_request("/api/0/buckets/test/heartbeat", {}) \ No newline at end of file From 45e053182ecd1736abff91ed8a1c8a77ac6c1423 Mon Sep 17 00:00:00 2001 From: Sadat Tarique Date: Tue, 16 Jun 2026 16:55:05 -0400 Subject: [PATCH 2/2] Add missing trailing newlines --- aw_client/client.py | 2 +- tests/test_requestqueue.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aw_client/client.py b/aw_client/client.py index 13eabfd..ff728af 100644 --- a/aw_client/client.py +++ b/aw_client/client.py @@ -557,4 +557,4 @@ def add_request(self, endpoint: str, data: dict) -> None: logger.warning(f"Failed to queue request, possibly due to insufficient disk space: {e}") def register_bucket(self, bucket_id: str, event_type: str) -> None: - self._registered_buckets.append(Bucket(bucket_id, event_type)) \ No newline at end of file + self._registered_buckets.append(Bucket(bucket_id, event_type)) diff --git a/tests/test_requestqueue.py b/tests/test_requestqueue.py index 117e61a..419fc2c 100644 --- a/tests/test_requestqueue.py +++ b/tests/test_requestqueue.py @@ -72,4 +72,4 @@ def raise_oserror(*args, **kwargs): rq._persistqueue.put = raise_oserror # type: ignore # Should not raise, the OSError should be caught internally and logged instead - rq.add_request("/api/0/buckets/test/heartbeat", {}) \ No newline at end of file + rq.add_request("/api/0/buckets/test/heartbeat", {})