circuitpython: BLE start_scan on 5.3.0 dies with MemoryError: memory allocation failed, allocating 65536 bytes - also 42241 bytes

I had a spate of these a fortnight ago and I just got one now on a CLUE running 5.3.0 and fairly recent libs (20200625). I’ve touched nothing near this part of my application recently. This is with active=False if it makes any difference and I have been using buffer_size=1536 for some time.

Listening for (<class 'Advertisement'>,)
Traceback (most recent call last):
  File "code.py", line 1520, in <module>
  File "code.py", line 914, in broadcastAndReceive
  File "code.py", line 691, in startScan
  File "adafruit_ble/__init__.py", line 235, in start_scan
MemoryError: memory allocation failed, allocating 65536 bytes

That number is clearly suspicious for being so large and for being 2^16.

Minor possibility this is data driven, perhaps a rogue received BLE packet could cause the library to do some unwise size allocations? Three other devices running same code at same time weren’t affected.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 31 (1 by maintainers)

Most upvoted comments

The normal way we would debug this is to set a breakpoint on the exception handler and look at the backtrace. That requires connecting a J-Link or similar to the board. That’s why I was hoping for a simpler example that occurs often enough to catch this, but I’m not sure that’s possible here. Do you think any of that is possible?

The other thing I am looking at is generating and printing a stack trace when these exceptions happen. It looks like this is possible, if we add -funwind-tables or the equivalent: https://www.google.com/search?q=backtrace+arm-none-eabi-gcc https://github.com/red-rocket-computing/backtrace etc.