-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix message reading causing OOM on a busy bus #28
Conversation
Why doesn't |
The code uses the If the code used the regular Source: Table 12-1 of the MCP2515 datasheet |
Ok, so this isn't a problem that we're loading the same rx buffers again. It is a control flow problem where we handle one message and load two over and over. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Updating https://github.com/adafruit/Adafruit_CircuitPython_APDS9960 to 3.1.14 from 3.1.13: > Merge pull request adafruit/Adafruit_CircuitPython_APDS9960#48 from FoamyGuy/fix_docs_build Updating https://github.com/adafruit/Adafruit_CircuitPython_CCS811 to 1.3.19 from 1.3.18: > Merge pull request adafruit/Adafruit_CircuitPython_CCS811#53 from FoamyGuy/remove_imp_usage Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP2515 to 1.1.8 from 1.1.7: > Merge pull request adafruit/Adafruit_CircuitPython_MCP2515#28 from SamantazFox/patch-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_PIOASM to 1.3.2 from 1.3.1: > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#76 from adafruit/fix-print-c-program
There is a logic error in the
unread_message_count
property getter that causes the library to buffer messages twice as fast as it empties the queue whenreceive()
is called.To give numbers, I simulated a busy bus (2* full length 8 bytes messages every ms) and it caused an OOM error in about 20 seconds. [1]
Assuming a fresh start (empty queue) and a moderately busy bus (the two Rx buffers of the MCP2515 are refilled between calls to
receive()
), here is what the code did:listener.in_waiting()
can.receive()
to read the first messagecan.receive()
to read the second messageAfter this PR, here is what the code does:
listener.in_waiting()
can.receive()
to read the first messagecan.receive()
to read the second messagelistener.in_waiting()
Here is the code used on either sides. Please note that the
Canbus
class is just boilerplate for initializing the CAN hardware. Switching between sender/receiver code requires (un)commenting the relevant lines inmain()
.Details
[1]: Fun fact, I initially wanted to simulate a moderately busy bus (about 40 to 60% load), but I left the baudrate to 250 kbit/s (instead of 500) from previous experiments, for which 2 fames/ms is almost a 100% bus load. My feather RP2040 CAN board handled that Tx rate nicely, though. The Rx board not so well ^^