PsychicHttp icon indicating copy to clipboard operation
PsychicHttp copied to clipboard

WebSocket handler core panic

Open T94T opened this issue 1 year ago • 6 comments

We really like this implementation of an http/https web server. Thanks a lot!

Currently we are experiencing a problem that is causing the ESP32 to crash.

WebSocket client: https://github.com/hoeken/PsychicHttp/blob/26b49f73dca48fa333361fb4a4cfeebca802eeda/examples/websockets/data/www/index.html

The ESP32 runs our custom firmware including the repository's example code:

server.on("/ws", &websocketHandler);
websocketHandler.onFrame([](PsychicWebSocketRequest *request, httpd_ws_frame *frame) {
  Serial.printf("[socket] #%d sent: %s\n", request->client()->socket(), (char *)frame->payload);
  return request->reply(frame);
});

Receiving WebSocket messages works fine without any errors. As soon as a packet is sent to the ESP32, it crashes:

[ 29135][I][PsychicWebSocket.cpp:175] handleRequest(): [psychic] frame len is 5
[ 29136][I][PsychicWebSocket.cpp:191] handleRequest(): [psychic] Got packet with message: TheMessage
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
#0  0x40111ae9:0x3ffd66d0 in httpd_sess_get at /esp_http_server/src/httpd_sess.c:173
#1  0x40112e19:0x3ffd6720 in httpd_ws_get_fd_info at /esp_http_server/src/httpd_ws.c:521
#2  0x400dba35:0x3ffd6740 in PsychicWebSocketHandler::handleRequest(PsychicRequest*) at .pio/libdeps/esp32-wroom/PsychicHttp/src/PsychicWebSocket.cpp:204 (discriminator 7)
#3  0x400dc0b9:0x3ffd6810 in PsychicEndpoint::requestCallback(httpd_req*) at .pio/libdeps/esp32-wroom/PsychicHttp/src/PsychicEndpoint.cpp:72
#4  0x401115b5:0x3ffd6890 in httpd_req_new at /esp_http_server/src/httpd_parse.c:776
#5  0x40111e2e:0x3ffd6930 in httpd_sess_process at /esp_http_server/src/httpd_sess.c:419 (discriminator 15)
#6  0x4010fb9c:0x3ffd6950 in httpd_process_session at /esp_http_server/src/httpd_main.c:178
    (inlined by) httpd_process_session at /esp_http_server/src/httpd_main.c:163
#7  0x4016e03a:0x3ffd6970 in httpd_sess_enum at /esp_http_server/src/httpd_sess.c:50 (discriminator 1)
#8  0x40110c40:0x3ffd6990 in httpd_server at /esp_http_server/src/httpd_main.c:228
    (inlined by) httpd_thread at /esp_http_server/src/httpd_main.c:250

The unmodified PlatformIO example (https://github.com/hoeken/PsychicHttp/tree/master/examples/websockets), on the other hand, works without any problems.

T94T avatar Jan 03 '24 08:01 T94T

I did a search in the code and in http idf to find the source of the problem but I couldn't find any ideas?

playmiel avatar Jan 11 '24 15:01 playmiel

Thank you for looking into it. We have not found a solution either.

T94T avatar Feb 01 '24 19:02 T94T

Take a look on the heap memory to be sure that's not full.

johnnytolengo avatar Feb 01 '24 19:02 johnnytolengo

I haven't been able to test it yet, but it's probably due to the "CORE_DEBUG_LEVEL=5" that I'd have to change to "CORE_DEBUG_LEVEL=2" or even less to fix the problem. Can you test it? (notably quoted here #65 )

playmiel avatar Feb 02 '24 11:02 playmiel

Just tried the CORE_DEBUG_LEVEL=2 setting and it does not crash anymore. On the other hand server.config.stack_size = 8192; has no effect and will still cause a core panic.

T94T avatar Feb 14 '24 12:02 T94T

related to: #74

T94T avatar Apr 26 '24 14:04 T94T

I think this is fixed, please re-open if necessary.

hoeken avatar Aug 10 '24 18:08 hoeken