Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Fix assertion errors#72

Merged
me-no-dev merged 3 commits into
me-no-dev:masterfrom
Bmooij:feature/fix_assertion_errors
Oct 14, 2019
Merged

Fix assertion errors#72
me-no-dev merged 3 commits into
me-no-dev:masterfrom
Bmooij:feature/fix_assertion_errors

Conversation

@Bmooij
Copy link
Copy Markdown
Contributor

@Bmooij Bmooij commented Oct 14, 2019

I don't know if it is correct.

For my project I'm using the Async Event Source Plugin from ESPAsyncWebServer.

My client contained a bug that initialized a SSE connection every second. After some time my ESP32 crashes and reboots. Needless to say I had to fix that bug in my client.

But from my opinion, the server should not crash/reboot from that issue. So I tried to pin point the problem.

A little background, when a SSE client connects, a welcome message is send back:

void Events::onLocalWebSocketConnected(AsyncEventSourceClient *client) {
    client->send("welcome", "message", getId());
}

First I wrote a python script that simulates my client bug. (Connect every second to the ESP32, for 500 times)

from sseclient import SSEClient
import threading
import time

def main():
    for x in range(0, 500):
        print("Connnection %d" % x)
        x = threading.Thread(target=sseClient)
        x.start()
        time.sleep(1)

def sseClient():
    messages = SSEClient('http://{ip}/events')

if __name__ == "__main__":
    main()

And indeed after some time the ESP32 crashes. I figured out that there where 2 issues. 1 is ESPAsyncWebServer related (I will open a pull request for that too) and 1 is AsyncTCP related.

The error that occurred that is AsyncTCP related:
assertion "invalid socket state for sent callback" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c", line 1842, function: tcp_sent

0x4008e2dc: invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c line 155
0x4008e50d: abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c line 170
0x401214bb: __assert_func at ../../../.././newlib/libc/stdlib/assert.c line 63
0x4013b6da: tcp_sent at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/tcp.c line 1842
0x40176640: AsyncClient::_error(signed char) at .pio\libdeps\development\AsyncTCP\src\AsyncTCP.cpp line 851
0x4017694b: _async_service_task(void*) at .pio\libdeps\development\AsyncTCP\src\AsyncTCP.cpp line 1211
0x4008a991: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

The problem was that an error occurred and the socket state was not LISTEN. When tcp_sent is called without the state LISTEN, an assertion error is thrown.

@Bmooij
Copy link
Copy Markdown
Contributor Author

Bmooij commented Oct 14, 2019

With this fix, the fix in ESPAsyncWebServer is irrelevant

@me-no-dev
Copy link
Copy Markdown
Owner

ha! those are changes in LwIP that I was not aware of :) definitely no need to call the functions with NULL anymore. But also interesting how nobody else had that error

@me-no-dev me-no-dev merged commit d27a12a into me-no-dev:master Oct 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants