boblemaire / asyncHTTPrequest

asynchronous HTTP for ESP using ESPasyncTCP. Works like XMLHTTPrequest in JS.
GNU General Public License v3.0
65 stars 31 forks source link

Crash on Loading Data #27

Closed lbussy closed 4 years ago

lbussy commented 4 years ago

When working with a debug version of a Django website, I noted that with a large document (this one was ~136k) the system will crash, I assume based on an overflow:

abort() was called at PC 0x40188863 on core 1
Backtrace: 0x4008c654:0x3ffd7f30 0x4008c885:0x3ffd7f50 0x40188863:0x3ffd7f70 0x401888aa:0x3ffd7f90 0x401883e9:0x3ffd7fb0 0x4018813c:0x3ffd7fd0 0x401880e9:0x3ffd7ff0 0x40110bcf:0x3ffd8010 0x40110c2e:0x3ffd8030 0x401107c1:0x3ffd8050 0x401108ed:0x3ffd8070 0x40189e91:0x3ffd8090 0x40189ee5:0x3ffd80c0 0x40189f29:0x3ffd80e0 0x4018a036:0x3ffd8100 0x4018a105:0x3ffd8120 0x40088c11:0x3ffd8150
  #0  0x4008c654:0x3ffd7f30 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:707
  #1  0x4008c885:0x3ffd7f50 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:707
  #2  0x40188863:0x3ffd7f70 in __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:112
  #3  0x401888aa:0x3ffd7f90 in std::terminate() at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_terminate.cc:112
  #4  0x401883e9:0x3ffd7fb0 in __cxa_allocate_exception at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/eh_alloc.cc:313
  #5  0x4018813c:0x3ffd7fd0 in operator new(unsigned int) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/new_op.cc:54
  #6  0x401880e9:0x3ffd7ff0 in operator new[](unsigned int) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/new_opv.cc:32
  #7  0x40110bcf:0x3ffd8010 in xbuf::addSeg() at .pio\libdeps\lolin_d32\asyncHTTPrequest\src/xbuf.cpp:80
  #8  0x40110c2e:0x3ffd8030 in xbuf::write(unsigned char const*, unsigned int) at .pio\libdeps\lolin_d32\asyncHTTPrequest\src/xbuf.cpp:80
  #9  0x401107c1:0x3ffd8050 in asyncHTTPrequest::_onData(void*, unsigned int) at .pio\libdeps\lolin_d32\asyncHTTPrequest\src/asyncHTTPrequest.cpp:187
  #10 0x401108ed:0x3ffd8070 in std::_Function_handler<void (void*, AsyncClient*, void*, unsigned int), asyncHTTPrequest::_onConnect(AsyncClient*)::{lambda(void*, AsyncClient*, void*, unsigned int)#2}>::_M_invoke(std::_Any_data const&, void*&&, AsyncClient*&&, std::_Any_data const&, unsigned int&&) at .pio\libdeps\lolin_d32\asyncHTTPrequest\src/asyncHTTPrequest.cpp:187
      (inlined by) _M_invoke at c:\users\xxxx\.platformio\packages\toolchain-xtensa32\xtensa-esp32-elf\include\c++\5.2.0/functional:1871
  #11 0x40189e91:0x3ffd8090 in std::function<void (void*, AsyncClient*, void*, unsigned int)>::operator()(void*, AsyncClient*, void*, unsigned int) const at .pio\libdeps\lolin_d32\AsyncTCP\src/AsyncTCP.cpp:1116
  #12 0x40189ee5:0x3ffd80c0 in AsyncClient::_recv(tcp_pcb*, pbuf*, signed char) at .pio\libdeps\lolin_d32\AsyncTCP\src/AsyncTCP.cpp:1116
  #13 0x40189f29:0x3ffd80e0 in AsyncClient::_s_recv(void*, tcp_pcb*, pbuf*, signed char) at .pio\libdeps\lolin_d32\AsyncTCP\src/AsyncTCP.cpp:1116
  #14 0x4018a036:0x3ffd8100 in _handle_async_event(lwip_event_packet_t*) at .pio\libdeps\lolin_d32\AsyncTCP\src/AsyncTCP.cpp:1116
  #15 0x4018a105:0x3ffd8120 in _async_service_task(void*) at .pio\libdeps\lolin_d32\AsyncTCP\src/AsyncTCP.cpp:1116
  #16 0x40088c11:0x3ffd8150 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)
Rebooting...

The function where it was rasied was:

  #10 0x401108ed:0x3ffd8070 in std::_Function_handler<void (void*, AsyncClient*, void*, unsigned int), asyncHTTPrequest::_onConnect(AsyncClient*)::{lambda(void*, AsyncClient*, void*, unsigned int)#2}>::_M_invoke(std::_Any_data const&, void*&&, AsyncClient*&&, std::_Any_data const&, unsigned int&&) at .pio\libdeps\lolin_d32\asyncHTTPrequest\src/asyncHTTPrequest.cpp:187

With debug turned on, I can see it receiving the lines till it eventually crashes.

Is there any way to maybe add a flag to "ignore body?"

boblemaire commented 4 years ago

Backstory: I wrote this class to support the IoTaWatt project , also in this account. That runs on an ESP8266, and serves my needs. I posted it in the event others might find it useful. Fast-forward, I have a port of IoTaWatt to ESP32, and added some threadsafe locking. It serves my needs fine for that as well.

Your issue is probably caused by a problem with flow control in the ESP32 AsyncTCP or my use of it. So larger transfers may be filling up heap and failing. If you are not interested in the response payload, you can discard it as it arrives by specifying an ondata callback and just dumping the data. See if that works.

lbussy commented 4 years ago

Appreciate the reply, Bob. I've done as you suggested and it's taken care of my issue. Thanks.