Webserver runs out of sockets

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Webserver runs out of sockets

Postby PeterR » Thu Sep 12, 2019 4:58 pm

I am using ESP-IDF the httpd webserver.
My webpage references many files, images etc.

Some HTTP clients make multiple requests before the last request has completed 'OK'.

This can cause ENFILE (23):

Code: Select all

 httpd_accept_conn() { ...
    int new_fd = accept(listen_fd, (struct sockaddr *)&addr_from, &addr_from_len);
    if (new_fd < 0) {
        ESP_LOGW(TAG, LOG_FMT("error in accept (%d)"), errno);
        return ESP_FAIL;
which I guess is being caused by

Code: Select all

lwip_accept() { ...
  newsock = alloc_socket(newconn, 1);
  if (newsock == -1) {
    netconn_delete(newconn);
    sock_set_errno(sock, ENFILE);
    return -1;
I have maxed the maximum number of open sockets.

Q) Does anyone have a patch e.g. stop httpd looping back into accept() until we have a free socket?
Q) Is the lwip socket limit per adaptor or per application?
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: No registered users and 126 guests