Skip to content

Commit ff2aa62

Browse files
authored
Merge pull request #28 from SamantazFox/patch-1
Fix message reading causing OOM on a busy bus
2 parents 6453da4 + 7e4c422 commit ff2aa62

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

adafruit_mcp2515/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,12 @@ def unread_message_count(self):
406406
Returns:
407407
int: The unread message count
408408
"""
409-
self._read_from_rx_buffers()
409+
410+
# Wait until the queue is empty before reading from the MCP2515 again,
411+
# otherwise we'll fill it faster than what the user app can process
412+
# and quickly run out of memory.
413+
if len(self._unread_message_queue) == 0:
414+
self._read_from_rx_buffers()
410415

411416
return len(self._unread_message_queue)
412417

0 commit comments

Comments
 (0)