From 96d8ace0e24477c3d238784fafc8e01fadc89153 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Mon, 20 Jan 2025 08:00:49 +0000 Subject: [PATCH 1/2] Fix message reading causing OOM on a busy bus --- adafruit_mcp2515/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_mcp2515/__init__.py b/adafruit_mcp2515/__init__.py index f19d197..3de646a 100644 --- a/adafruit_mcp2515/__init__.py +++ b/adafruit_mcp2515/__init__.py @@ -406,7 +406,8 @@ def unread_message_count(self): Returns: int: The unread message count """ - self._read_from_rx_buffers() + if len(self._unread_message_queue) == 0: + self._read_from_rx_buffers() return len(self._unread_message_queue) From 7e4c42272bcd6f9b4e42f4ac4a9f7090100fe794 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 23 Jan 2025 12:03:54 +0000 Subject: [PATCH 2/2] Add comment explaining why we wait before reading --- adafruit_mcp2515/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_mcp2515/__init__.py b/adafruit_mcp2515/__init__.py index 3de646a..a96ccf5 100644 --- a/adafruit_mcp2515/__init__.py +++ b/adafruit_mcp2515/__init__.py @@ -406,6 +406,10 @@ def unread_message_count(self): Returns: int: The unread message count """ + + # Wait until the queue is empty before reading from the MCP2515 again, + # otherwise we'll fill it faster than what the user app can process + # and quickly run out of memory. if len(self._unread_message_queue) == 0: self._read_from_rx_buffers()