Skip to content

Add optional clearing of scan results when stopping scan. #304

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

Closed
wants to merge 1 commit into from

Conversation

h2zero
Copy link
Owner

@h2zero h2zero commented Oct 16, 2021

This resolves a possible collision when scanning is active and a call to connect to a device is made.

When the scanner is still active in a continuous scan the results may be pushed at the same time as clearing them in the call to stop scanning when attempting to connect to a device. This propses to add a parameter to the scan stop call to not clear the scan results in this scenario and may be useful for other use cases.

This resolves a possible collision when scanning is active and a call to connect to a device is made.

When the scanner is still active in a continuous scan the results may be pushed at the same time as clearing them in the call to stop
scanning when attempting to connect to a device. This propses to add a parameter to the scan stop call to not clear the scan results in
this scenario and may be useful for other use cases.
@DTTerastar
Copy link

Backtrace: 0x40090220:0x3ffea370 0x4009049d:0x3ffea390 0x4008778d:0x3ffea3b0 0x400878b9:0x3ffea3e0 0x40126fcb:0x3ffea400 0x40120a71:0x3ffea6c0 0x401209f5:0x3ffea710 0x400951f9:0x3ffea740 0x4008291e:0x3ffea760 0x40087685:0x3ffea780 0x4000bec7:0x3ffea7a0 0x401ab335:0x3ffea7c0 0x400e074e:0x3ffea7e0 0x400e0921:0x3ffea810 0x400e3dce:0x3ffea850 0x400e8c9d:0x3ffea8c0 0x400e8d49:0x3ffea900 0x400e8f95:0x3ffea920 0x400e7859:0x3ffea940 0x400ee9be:0x3ffea960 0x400dff57:0x3ffea980 0x400914ae:0x3ffea9a0
  #0  0x40090220:0x3ffea370 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #1  0x4009049d:0x3ffea390 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #2  0x4008778d:0x3ffea3b0 in lock_acquire_generic at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/locks.c:143
  #3  0x400878b9:0x3ffea3e0 in _lock_acquire_recursive at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/locks.c:171
  #4  0x40126fcb:0x3ffea400 in _vfiprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:860 (discriminator 2)
  #5  0x40120a71:0x3ffea6c0 in fiprintf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fiprintf.c:50
  #6  0x401209f5:0x3ffea710 in __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:59 (discriminator 8)
  #7  0x400951f9:0x3ffea740 in multi_heap_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c:305
  #8  0x4008291e:0x3ffea760 in heap_caps_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:232
  #9  0x40087685:0x3ffea780 in _free_r at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/syscalls.c:42
  #10 0x4000bec7:0x3ffea7a0 in ?? ??:0
  #11 0x401ab335:0x3ffea7c0 in operator delete(void*) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/del_op.cc:46
  #12 0x400e074e:0x3ffea7e0 in __gnu_cxx::new_allocator<unsigned char>::deallocate(unsigned char*, unsigned int) at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/NimBLEScan.cpp:408
      (inlined by) std::allocator_traits<std::allocator<unsigned char> >::deallocate(std::allocator<unsigned char>&, unsigned char*, unsigned int) at /Users/dturner/.platformio/packages/toolchain-xtensa32@2.50200.97/xtensa-esp32-elf/include/c++/5.2.0/bits/alloc_traits.h:386
      (inlined by) std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_deallocate(unsigned char*, unsigned int) at /Users/dturner/.platformio/packages/toolchain-xtensa32@2.50200.97/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:178
      (inlined by) std::_Vector_base<unsigned char, std::allocator<unsigned char> >::~_Vector_base() at /Users/dturner/.platformio/packages/toolchain-xtensa32@2.50200.97/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:160
      (inlined by) std::vector<unsigned char, std::allocator<unsigned char> >::~vector() at /Users/dturner/.platformio/packages/toolchain-xtensa32@2.50200.97/xtensa-esp32-elf/include/c++/5.2.0/bits/stl_vector.h:425
      (inlined by) NimBLEAdvertisedDevice::~NimBLEAdvertisedDevice() at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/NimBLEAdvertisedDevice.h:40
      (inlined by) NimBLEScan::erase(NimBLEAddress const&) at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/NimBLEScan.cpp:423
  #13 0x400e0921:0x3ffea810 in NimBLEScan::handleGapEvent(ble_gap_event*, void*) at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/NimBLEScan.cpp:408
  #14 0x400e3dce:0x3ffea850 in ble_gap_disc_report at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/nimble/host/src/ble_gap.c:6168
      (inlined by) ble_gap_rx_adv_report at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/nimble/host/src/ble_gap.c:1499
  #15 0x400e8c9d:0x3ffea8c0 in ble_hs_hci_evt_le_adv_rpt at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/nimble/host/src/ble_hs_hci_evt.c:501
  #16 0x400e8d49:0x3ffea900 in ble_hs_hci_evt_le_meta at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/nimble/host/src/ble_hs_hci_evt.c:301
  #17 0x400e8f95:0x3ffea920 in ble_hs_hci_evt_process at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/nimble/host/src/ble_hs_hci_evt.c:859
  #18 0x400e7859:0x3ffea940 in ble_hs_event_rx_hci_ev at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/nimble/nimble_npl_os.h:109
  #19 0x400ee9be:0x3ffea960 in ble_npl_event_run at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/porting/nimble/src/nimble_port.c:130
      (inlined by) nimble_port_run at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/porting/nimble/src/nimble_port.c:81
  #20 0x400dff57:0x3ffea980 in NimBLEDevice::host_task(void*) at .pio/libdeps/m5atom-matrix/NimBLE-Arduino/src/NimBLEDevice.cpp:855 (discriminator 1)
  #21 0x400914ae:0x3ffea9a0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

@h2zero
Copy link
Owner Author

h2zero commented Oct 17, 2021

The call stack in this looks odd. Can you provide more of the log? Also the register dump would help.

@h2zero
Copy link
Owner Author

h2zero commented Oct 19, 2021

I've been able to reproduce some similar errors to this. The problem results mainly from calling NimBLEScan::start() in a loop. I'm still trying to recreate the same crash as this but it seems very random and can take hours before it happens.

In your project I propose 2 possible solutions, put the scan task on core 0, or wrap the call in the loop to start the scan with if (!pBLEScan->isScanning())

In the meantime I will see what can be done to prevent this once I can trigger more crashes.

@DTTerastar
Copy link

OK, i've made the if (!pBLEScan->isScanning()) change and will report back on uptime

@DTTerastar
Copy link

8 hours uptime so far! MUCH better.

@DTTerastar
Copy link

Yeah, You can close this we're good.

@h2zero h2zero closed this Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants