Skip to content

Commit

Permalink
fix(esp_http_client): Fix ota failure with openssl server
Browse files Browse the repository at this point in the history
If the TLS server (e.g., openssl) closes connection with encrypted close-notify alert
then `errno` is not explicitly set on the socket by LwIP stack.
For this scenario, we must rely only on `ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN`
return value as the connection close case and do the graceful connection closure.

Closes #14724
  • Loading branch information
nileshkale123 committed Nov 21, 2024
1 parent 907337a commit 1608b89
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions components/esp_http_client/esp_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,15 +1192,15 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len)
ESP_LOGD(TAG, "need_read=%d, byte_to_read=%d, rlen=%d, ridx=%d", need_read, byte_to_read, rlen, ridx);

if (rlen <= 0) {
esp_log_level_t sev = ESP_LOG_WARN;
/* Check for cleanly closed connection */
if (rlen == ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN && client->response->is_chunked) {
/* Explicit call to parser for invoking `message_complete` callback */
http_parser_execute(client->parser, client->parser_settings, res_buffer->data, 0);
/* ...and lowering the message severity, as closed connection from server side is expected in chunked transport */
sev = ESP_LOG_DEBUG;
}
if (errno != 0) {
esp_log_level_t sev = ESP_LOG_WARN;
/* Check for cleanly closed connection */
if (rlen == ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN && client->response->is_chunked) {
/* Explicit call to parser for invoking `message_complete` callback */
http_parser_execute(client->parser, client->parser_settings, res_buffer->data, 0);
/* ...and lowering the message severity, as closed connection from server side is expected in chunked transport */
sev = ESP_LOG_DEBUG;
}
ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno);
}

Expand Down

0 comments on commit 1608b89

Please sign in to comment.