esp-idf: httpd: httpd_accept_conn: error in accept (23) (IDFGH-9118)
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
General issue report
IDF version : v4.3.4-dirty
When open the first web page in the browser,it works fine.Then open a new page in other browser,some source can’t load. I have set lwip max socket num =16. And I also used socket in other places,such as tcp server,tcp client,mqtt… I have read the #9395 and add the code bellow in web server config.
void close_fd_cb(httpd_handle_t hd, int sockfd)
{
struct linger so_linger;
so_linger.l_onoff = true;
so_linger.l_linger = 0;
setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof(so_linger));
close(sockfd);
ESP_LOGI(TAG, "close() fd (%d) success.", sockfd);
}
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
config.uri_match_fn = httpd_uri_match_wildcard;
config.max_uri_handlers = 64;
config.max_open_sockets = 12;
config.lru_purge_enable = true;
config.close_fn = close_fd_cb;
It seems difficult to trigger。Rarely seen “close() fd (%d) success.”
the error lwip log is bellow:
lwip_accept(48)...
[0;33mW (34520) httpd: httpd_accept_conn: error in accept (23)[0m
[0;33mW (34521) httpd: httpd_server: error accepting new connection[0m
lwip_select(64, 0x3ffcbb90, 0x0, 0x0, tvsec=-1 tvusec=-1)
lwip_selscan: fd=48 ready for reading
lwip_selscan: fd=61 ready for reading
lwip_selscan: fd=62 ready for reading
lwip_select: nready=3
lwip_recvfrom(61, 0x3ffc8fb8, 128, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x0
lwip_recv_tcp: netconn_recv err=0, pbuf=0x3ffcd05c
lwip_recv_tcp: buflen=381 recv_left=128 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd05c
lwip_recvfrom(61): addr=192.168.3.110 port=3991 len=128
lwip_recvfrom(61, 0x3ffc9018, 128, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd05c
lwip_recv_tcp: buflen=253 recv_left=128 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd05c
lwip_recvfrom(61): addr=192.168.3.110 port=3991 len=128
lwip_recvfrom(61, 0x3ffc9098, 128, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd05c
lwip_recv_tcp: buflen=125 recv_left=128 off=0
lwip_recv_tcp: deleting pbuf=0x3ffcd05c
lwip_recv_tcp: top while sock->lastdata=0x0
lwip_recv_tcp: netconn_recv err=-7, pbuf=0x0
lwip_recvfrom(61): addr=192.168.3.110 port=3991 len=125
lwip_send(61, data=0x3ffc8fb8, size=78, flags=0x0)
lwip_send(61) err=0 written=78
lwip_send(61, data=0x3f4c4454, size=2, flags=0x0)
lwip_send(61) err=0 written=2
lwip_send(61, data=0x3f466525, size=37051, flags=0x0)
lwip_send(61) err=0 written=37051
lwip_recvfrom(62, 0x3ffc8fb8, 128, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x0
lwip_recv_tcp: netconn_recv err=0, pbuf=0x3ffcd120
lwip_recv_tcp: buflen=376 recv_left=128 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd120
lwip_recvfrom(62): addr=192.168.3.110 port=3992 len=128
lwip_recvfrom(62, 0x3ffc901d, 128, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd120
lwip_recv_tcp: buflen=248 recv_left=128 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd120
lwip_select: timeout expired
lwip_recvfrom(62): addr=192.168.3.110 port=3992 len=128
lwip_select(61, 0x3ffd1468, 0x0, 0x3ffd1470, tvsec=0 tvusec=0)
lwip_select: no timeout, returning 0
lwip_recvfrom(62, 0x3ffc909d, 128, 0x0, ..)
lwip_select(61, 0x3ffd1518, 0x0, 0x3ffd1520, tvsec=1 tvusec=0)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd120
lwip_recv_tcp: buflen=120 recv_left=128 off=0
lwip_recv_tcp: deleting pbuf=0x3ffcd120
lwip_recv_tcp: top while sock->lastdata=0x0
lwip_recv_tcp: netconn_recv err=-7, pbuf=0x0
lwip_recvfrom(62): addr=192.168.3.110 port=3992 len=120
lwip_send(62, data=0x3ffc8fb8, size=78, flags=0x0)
lwip_send(62) err=0 written=78
lwip_send(62, data=0x3f4c4454, size=2, flags=0x0)
lwip_send(62) err=0 written=2
lwip_send(62, data=0x3f4a72b5, size=31567, flags=0x0)
lwip_send(62) err=0 written=31567
lwip_accept(48)...
[0;33mW (34818) httpd: httpd_accept_conn: error in accept (23)[0m
[0;33mW (34819) httpd: httpd_server: error accepting new connection[0m
lwip_select(64, 0x3ffcbb90, 0x0, 0x0, tvsec=-1 tvusec=-1)
lwip_select: timeout expired
lwip_select(61, 0x3ffd1468, 0x0, 0x3ffd1470, tvsec=0 tvusec=0)
lwip_select: no timeout, returning 0
lwip_select(61, 0x3ffd1518, 0x0, 0x3ffd1520, tvsec=1 tvusec=0)
lwip_select: timeout expired
lwip_select(61, 0x3ffd1468, 0x0, 0x3ffd1470, tvsec=0 tvusec=0)
lwip_select: no timeout, returning 0
lwip_select(61, 0x3ffd1518, 0x0, 0x3ffd1520, tvsec=1 tvusec=0)
lwip_selscan: fd=59 ready for reading
lwip_select: nready=1
lwip_recvfrom(59, 0x3ffcba80, 1, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x0
lwip_recv_tcp: netconn_recv err=0, pbuf=0x3ffcd120
lwip_recv_tcp: buflen=29 recv_left=1 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd120
lwip_recvfrom(59): addr=192.168.3.110 port=3977 len=1
lwip_recvfrom(59, 0x3ffcba60, 1, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd120
lwip_recv_tcp: buflen=28 recv_left=1 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd120
lwip_recvfrom(59): addr=192.168.3.110 port=3977 len=1
lwip_recvfrom(59, 0x3ffcba61, 4, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd120
lwip_recv_tcp: buflen=27 recv_left=4 off=0
lwip_recv_tcp: lastdata now pbuf=0x3ffcd120
lwip_recvfrom(59): addr=192.168.3.110 port=3977 len=4
lwip_recvfrom(59, 0x3ffcba90, 23, 0x0, ..)
lwip_recv_tcp: top while sock->lastdata=0x3ffcd120
lwip_recv_tcp: buflen=23 recv_left=23 off=0
lwip_recv_tcp: deleting pbuf=0x3ffcd120
lwip_recvfrom(59): addr=192.168.3.110 port=3977 len=23
lwip_send(59, data=0x3ffcba10, size=4, flags=0x0)
lwip_send(59) err=0 written=4
lwip_send(59, data=0x3ffcc538, size=627, flags=0x0)
lwip_send(59) err=0 written=627
lwip_select(64, 0x3ffcbb90, 0x0, 0x0, tvsec=-1 tvusec=-1)
lwip_select: timeout expired
lwip_select(61, 0x3ffd1468, 0x0, 0x3ffd1470, tvsec=0 tvusec=0)
lwip_select: no timeout, returning 0
lwip_select(61, 0x3ffd1518, 0x0, 0x3ffd1520, tvsec=1 tvusec=0)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (2 by maintainers)
@ArvinHou I think you can follow this patch to add keep-alive function.
And when you close web page, the browser may not close socket, so when you close browser, it will release the previous sockets.