Open
@ctschach

Description

Hi,

I have a function that scans for advertising data and decode the information (Ruuvi temperature sensors). However, when this runs for a while together with some other tasks, I'm running into a memory issue.

Unhandled exception in IRQ callback handler
Traceback (most recent call last):
  File "core.py", line 71, in ble_irq
  File "central.py", line 61, in _central_irq
MemoryError: memory allocation failed, allocating 2048 bytes

This will quit my background BLE scanning task which is updating my temperature data. Of course I can watch the task and restart it, but I hope for a better error handling the the aioble library.

It runs fine for quite some time before it giving the error. It's not reproducible - sometimes it occurs after 5 minutes, sometimes it runs 2h without any issues.

I tried running an exception catcher around the can itself:

        try:
            async with aioble.scan(duration_ms = duration, interval_us=30000, window_us=30000, active = True) as scanner:
                self.scanner = scanner
                async for result in scanner:
                    self._handle_advertisement(result)

        except Exception as e:
            print('!!!!! Exception in aioble scan')
            print(e)

But this doesn't help to prevent the error from happing. Of course I could change the code in central.py myself and see if I can catch the error, but I don't want to mess around with it (yet).

I already have another task that is frequently running a gc.collect() and memory shows up with round 32kB.

Thanks....