Page 1 of 1

ESP32 websocket client fails after 1 hour with multiple errors

Posted: Thu Apr 18, 2024 1:32 am
by nandishre
presently i am using ESP32 wroom and working on esp32 websockt client, till one hour module is stable , after an hpur websocket fails but some time says socket disconnected and if try to reconnect it says,
<ESC>[0;31mE (6356662) transport_base: tcp_write error, errno=No more processes<ESC>[0m<CR><LF>
<ESC>[0;31mE (6356662) websocket_client: esp_transport_write() returned -1, transport_error=ESP_OK, tls_error_code=0, tls_flags=0, errno=11<ESC>[0m<CR><LF>

after some if we retry to connect then (6417422) websocket_client: esp_websocket_client_init(596): Memory exhausted<ESC>[0m<CR><LF> later error continuous and we cant make websocket conenction, need to restart the module to make websocket connection

need suggestions


regards
Nandy

Re: ESP32 websocket client fails after 1 hour with multiple errors

Posted: Thu Apr 18, 2024 1:27 pm
by limpens
Memory exhausted looks like you are running out of memory.

Can't help without some context or source code, but you might check if you free buffers after transmitting them.

When I use httpd_ws_send_frame_async, I know to release the buffers.

Re: ESP32 websocket client fails after 1 hour with multiple errors

Posted: Sat Apr 20, 2024 11:55 am
by nandishre
esp_websocket_client_send_text(_socket, databuff, strlen(databuff), portMAX_DELAY);

i use this line of code to transmit data , as databuff is local variable with fixed length of 1024. but i see memory exhaust issue is coming from internal stack. but i dont know how to clear the buffer in this context

Re: ESP32 websocket client fails after 1 hour with multiple errors

Posted: Sat Apr 20, 2024 12:21 pm
by nandishre
little more specific ,

after we send data to websockt after some time get below error
<ESC>[0m<CR><LF>
<ESC>[0;31mE (6336342) transport_base: tcp_write error, errno=No more processes<ESC>[0m<CR><LF>
<ESC>[0;31mE (6336342) transport_ws: Error write header<ESC>[0m<CR><LF>
<ESC>[0;31mE (6336342) websocket_client: esp_transport_write() returned -1, transport_error=ESP_OK, tls_error_code=0, tls_flags=0, errno=11<ESC>[0m<CR><LF>
<ESC>[0;33mW (6336352) OCPP_1.6: SOCKET ERROR<ESC>[0m<CR><LF>
<ESC>[0;31mE (6336362) OCPP_1.6: SOCKET DISCONNECTED<ESC>[0m<CR><LF>
<ESC>[0;31mE (6336362) websocket_client: Failed to send the buffer<ESC>[0m<CR><LF>

after this we retry to connect to websocket and get below error

20-04-2024 17:02:28.529 [RX] - <ESC>[0;31mE (6347162) websocket_client: Error create websocket task<ESC>[0m<CR><LF>

20-04-2024 17:02:38.528 [RX] - <ESC>[0;31mE (6357162) websocket_client: Error create websocket task<ESC>[0m<CR><LF>

20-04-2024 17:02:48.529 [RX] - <ESC>[0;31mE (6367162) websocket_client: Error create websocket task<ESC>[0m<CR><LF>

20-04-2024 17:02:58.527 [RX] - <ESC>[0;31mE (6377162) websocket_client: esp_websocket_client_set_uri(748): Memory exhausted<ESC>[0m<CR><LF>
<ESC>[0;31mE (6377162) websocket_client: Invalid uri<ESC>[0m<CR><LF>

this is after 3 times fail , 4th time we get memory exhaust issue, this behvious we ahev seen after 1 hour:40 mins

i am clueless on the issue, i am doing memset after the data sent to cloud , no malloc functions used

Re: ESP32 websocket client fails after 1 hour with multiple errors

Posted: Sun Apr 21, 2024 7:46 pm
by djixon
Did you try using esp_websocket_client_send_buffer() function instead using esp_websocket_client_send_text()? That function which sends text (string) expects null termination on that string because you are using strlen() function in that call. If some string passed accidentally withou null termination its whops..... trouble because strlen() is going to get mad, probably making flood fill on your stack

Or at least make an extra check that each string passed to that function is properly null terminated.