yubox-node-org / AsyncTCPSock

Reimplementation of the API of me-no-dev/AsyncTCP using high-level BSD sockets
GNU Lesser General Public License v3.0
20 stars 10 forks source link

Crash on cold page load. #20

Open zekageri opened 1 year ago

zekageri commented 1 year ago
[1750479][E][AsyncTCP.cpp:797] _flushWriteQueue(): socket 50 lwip_write() failed errno=104

assert failed: xQueueSemaphoreTake queue.c:1545 (( pxQueue ))

Backtrace: 0x40083d69:0x3ffdd880 0x4008eeb1:0x3ffdd8a0 0x400948b5:0x3ffdd8c0 0x4008fec1:0x3ffdd9f0 0x401b08fb:0x3ffdda30 0x401b0a5c:0x3ffdda50 0x401b0ba3:0x3ffdda80 0x401b0eb5:0x3ffddab0 0x401b0293:0x3ffddb10

  #0  0x40083d69:0x3ffdd880 in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:402
  #1  0x4008eeb1:0x3ffdd8a0 in esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c:128  
  #2  0x400948b5:0x3ffdd8c0 in __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c:85
  #3  0x4008fec1:0x3ffdd9f0 in xQueueSemaphoreTake at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/freertos/queue.c:1549 (discriminator 1)
  #4  0x401b08fb:0x3ffdda30 in std::_Deque_iterator<AsyncClient::queued_writebuf, AsyncClient::queued_writebuf&, AsyncClient::queued_writebuf*>::difference_type std::operator-<AsyncClient::queued_writebuf, AsyncClient::queued_writebuf&, AsyncClient::queued_writebuf*>(std::_Deque_iterator<AsyncClient::queued_writebuf, AsyncClient::queued_writebuf&, AsyncClient::queued_writebuf*> const&, std::_Deque_iterator<AsyncClient::queued_writebuf, AsyncClient::queued_writebuf&, AsyncClient::queued_writebuf*> const&) at c:\users\pc\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/stl_deque.h:357
  #5  0x401b0a5c:0x3ffdda50 in AsyncClient::_error(signed char) at lib/AsyncTCPSock/src/AsyncTCP.cpp:986
  #6  0x401b0ba3:0x3ffdda80 in __gnu_cxx::new_allocator<AsyncClient::notify_writebuf>::deallocate(AsyncClient::notify_writebuf*, unsigned int) at c:\users\pc\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\ext/new_allocator.h:125    
      (inlined by) std::allocator_traits<std::allocator<AsyncClient::notify_writebuf> >::deallocate(std::allocator<AsyncClient::notify_writebuf>&, AsyncClient::notify_writebuf*, unsigned int) at c:\users\pc\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/alloc_traits.h:462
      (inlined by) std::_Deque_base<AsyncClient::notify_writebuf, std::allocator<AsyncClient::notify_writebuf> >::_M_deallocate_node(AsyncClient::notify_writebuf*) at c:\users\pc\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/stl_deque.h:610
      (inlined by) std::deque<AsyncClient::notify_writebuf, std::allocator<AsyncClient::notify_writebuf> >::_M_pop_front_aux() at c:\users\pc\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/deque.tcc:568
      (inlined by) std::deque<AsyncClient::notify_writebuf, std::allocator<AsyncClient::notify_writebuf> >::pop_front() at c:\users\pc\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/stl_deque.h:1599
      (inlined by) AsyncClient::_notifyWrittenBuffers(std::deque<AsyncClient::notify_writebuf, std::allocator<AsyncClient::notify_writebuf> >&, int) at lib/AsyncTCPSock/src/AsyncTCP.cpp:842
  #7  0x401b0eb5:0x3ffddab0 in AsyncClient::_sockIsWriteable() at lib/AsyncTCPSock/src/AsyncTCP.cpp:728
  #8  0x401b0293:0x3ffddb10 in _asynctcpsock_task(void*) at lib/AsyncTCPSock/src/AsyncTCP.cpp:138

ELF file SHA256: d0cb80949abd78a8

Rebooting...

Here is the relevant part in AsyncTCP.cpp

bool AsyncClient::_flushWriteQueue(void)
{
    bool activity = false;

    if (_socket == -1) return false;

    for (auto it = _writeQueue.begin(); it != _writeQueue.end(); it++) {
        // Abort iteration if error found while writing a buffer
        if (it->write_errno != 0) break;

        // Skip over head buffers already fully written
        if (it->written >= it->length) continue;

        bool keep_writing = true;
        do {
            uint8_t * p = it->data + it->written;
            size_t n = it->length - it->written;
            errno = 0;
            ssize_t r;

#if ASYNC_TCP_SSL_ENABLED
            if (_sslctx != NULL) {
                r = _sslctx->write(p, n);
                if (ASYNCTCP_TLS_CAN_RETRY(r)) {
                    r = -1;
                    errno = EAGAIN;
                } else if (ASYNCTCP_TLS_EOF(r)) {
                    r = -1;
                    errno = EPIPE;
                } else if (r < 0) {
                    if (errno == 0) errno = EIO;
                }
            } else {
#endif
                r = lwip_write(_socket, p, n);
#if ASYNC_TCP_SSL_ENABLED
            }
#endif

            if (r >= 0) {
                // Written some data into the socket
                it->written += r;
                _writeSpaceRemaining += r;
                activity = true;

                if (it->written >= it->length) {
                    it->written_at = millis();
                    if (it->owned) ::free(it->data);
                    it->data = NULL;
                }
            } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
                // Socket is full, could not write anything
                keep_writing = false;
            } else {
                // A write error happened that should be reported
                it->write_errno = errno;
                keep_writing = false;
                log_e("socket %d lwip_write() failed errno=%d", _socket, it->write_errno);
            }
        } while (keep_writing && it->written < it->length);
    }

    return activity;
}