Esp32S3 : Error during http receive - httpd_txrx: httpd_sock_err: error in recv : 104

ThomasESP32
Posts: 281
Joined: Thu Jul 14, 2022 5:15 am

Esp32S3 : Error during http receive - httpd_txrx: httpd_sock_err: error in recv : 104

Postby ThomasESP32 » Tue Sep 30, 2025 1:06 pm

Good afternoon,


I am working with an Esp32S3 and I am using the Wifi in order to receive chuncks of file sent by an application on a Smartphone.
In order to do that, I declared a httpd_uri_t structure that way :

httpd_uri_t update_post = {
.uri = "/POST",
.method = HTTP_POST,
.handler = update_post_handler,
.user_ctx = NULL
};

In the update_post_handler, I am doing a loop in order to receive the chunks of the file :

while (remaining > 0)
{
int recv_len = httpd_req_recv(req, buf, MIN(remaining, sizeof(buf)));

if (recv_len == HTTPD_SOCK_ERR_FAIL)
DbgFrames::SendFrame("Wifi : StdFileSystem - Write Sock Err Fail !");
else if (recv_len == HTTPD_SOCK_ERR_INVALID)
DbgFrames::SendFrame("Wifi : StdFileSystem - Write Sock Err Invalid !");

// Timeout Error: Just retry
if (recv_len == HTTPD_SOCK_ERR_TIMEOUT)
{
FailCounter++;
if (FailCounter >= WIFI_FAIL_COUNTER_MAX_VALUE)
{
pStdIntFAT = nullptr;
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "HTTPD Socket Error Timeout, exit process !\n");
return ESP_FAIL;
}
continue;
// Serious Error: Abort OTA
}
else if (recv_len <= 0)
{
pStdIntFAT = nullptr;
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Protocol Error, exit process !\n");
return ESP_FAIL;
}

// Successful Upload: Flash StdFAT chunk
if (esp_partition_write(pStdIntFAT, RecordedSize, (const void *)buf, recv_len) != ESP_OK)
{
pStdIntFAT = nullptr;
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Flash Error, exit process !\n");
return ESP_FAIL;
}

RecordedSize += recv_len;
FailCounter = 0;
remaining -= recv_len;
}

The problem is the following : When I close the application on Smartphone while the File is being sent, I get an error message :
[0;33mW (80335) httpd_txrx: httpd_sock_err: error in recv : 104[0m
That is displayed on my console.

When the message is received, the program exits from the while loop and continues to execute normally.
I would like to be able to catch the error in my loop and exit from my function with a (return ESP_FAIL) instruction
before exiting from the while loop.

Do you know how I can detect the error condition please ?
Thank you for your help on this subject.

Best regards,

Who is online

Users browsing this forum: Applebot, Baidu [Spider], Bytespider, Qwantbot, YisouSpider and 4 guests