HTTP_Server: Error accepting connections when polling webserver functions from JavaScript

bewatermyfriendxd
Posts: 9
Joined: Wed Apr 03, 2019 1:29 pm

HTTP_Server: Error accepting connections when polling webserver functions from JavaScript

Postby bewatermyfriendxd » Wed Apr 17, 2019 10:19 am

Hello,

Im using a webserver on my ESP32 which provides functions I can access from the web page via HTTP methods.
On one page I poll values from the ESP32 using JavaScript code like this:

Code: Select all

var xhr = new XMLHttpRequest();
xhr.open("POST", '/server/readADC', true);

xhr.onreadystatechange = function() 
{
    if (this.readyState === 4 && this.status === 200) {
        // Visualize data on the website
    }
}
The problem is, the server stops responding after a few requests.
After some time I get this error on the ESP32 side.

W (582011) httpd: httpd_accept_conn: error in accept (23)
W (582011) httpd: httpd_server: error accepting new connection
W (582021) httpd: httpd_accept_conn: error in accept (23)
W (582021) httpd: httpd_server: error accepting new connection
W (583011) httpd: httpd_accept_conn: error in accept (23)


Ive configured the http server with HTTPD_DEFAULT_CONFIG() value.
How am I able to continuously fetch data from the http server?

I'll appreciate any help. Thanks for the support.

bewatermyfriendxd
Posts: 9
Joined: Wed Apr 03, 2019 1:29 pm

Re: HTTP_Server: Error accepting connections when polling webserver functions from JavaScript

Postby bewatermyfriendxd » Thu Apr 18, 2019 9:08 am

I could fix this issue by modifying the http_config struct I used to initialize the http server.
When using the macro HTTPD_DEFAULT_CONFIG() the field lru_pruge_enable is set to false.
I had to set this true.

This field is described as
Purge "Least Recently Used" connection
.
When doing something like polling from JavaScript a lot of requests are sent to the http_server, for each a new session is opened by the internal socket. At some point the socket cant keep up anymore. By setting this field the socket throws away the last session and replaces it with the new request. So all requests can be properly handled.

Return to “ESP32 IDF”

Who is online

Users browsing this forum: DannyBackx and 8 guests