Server hangs inside httpd_resp_send_chunk when client goes away

mchahn
Posts: 17
Joined: Fri Sep 18, 2020 6:31 am

Server hangs inside httpd_resp_send_chunk when client goes away

Postby mchahn » Sat Jun 19, 2021 6:53 pm

I'm serving chunked mjpeg from an esp32-cam (thinkertoy). I know my code can't handle more than one client request at a time. But I'd at least like to be able to close a browser window showing the video and then have the server cleanly close the http connection. Then another browser could start viewing the video.

Right now, when the client disappears, the server hangs in a httpd_resp_send_chunk call and never returns. So there is no way inside the handler to close the stream with p_send_chunk(req, NULL, 0);

I tried saving the req pointer globally and then doing the p_send_chunk(req, NULL, 0); from an outside loop timeout but that crashed the esp32 (not a big surprise).

Any ideas?

mchahn
Posts: 17
Joined: Fri Sep 18, 2020 6:31 am

Re: Server hangs inside httpd_resp_send_chunk when client goes away

Postby mchahn » Sun Jun 20, 2021 5:49 pm

It occurs to me that having the send_chunk call time out would be ideal. Is there a way to set a timeout for send_chunk or a tcp connection in general? Is there a way to set a timeout for a raw response? Could I code the chunk responses using raw or is raw hard-wired to close the response?

Is the source code for the espressif http server available for me to look at?

ESP_Sprite
Posts: 9725
Joined: Thu Nov 26, 2015 4:08 am

Re: Server hangs inside httpd_resp_send_chunk when client goes away

Postby ESP_Sprite » Mon Jun 21, 2021 1:04 am

Yes it is, in esp-idf/components/esp_http_server/src/ , specifically the code you're looking for is in httpd_txrx.c

mchahn
Posts: 17
Joined: Fri Sep 18, 2020 6:31 am

Re: Server hangs inside httpd_resp_send_chunk when client goes away

Postby mchahn » Mon Jun 21, 2021 4:30 am

Thanks.

I found different code for the esp32 cameras. It uses WebServer inside tasks without chunking and the code not only handles disconnects but allows up to 10 connections at once. That gets me around the send chunk hangups, assuming it works. I'm going to give that a try.

I'm curious about the difference between WebServer and esp_http_server. I'm going to google that.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 126 guests