Skip to content

Commit cc73468

Browse files
committed
fix(esp_http_client): Fix ota failure with openssl server
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
1 parent f42bc63 commit cc73468

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

components/esp_http_client/esp_http_client.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,15 +1192,15 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len)
11921192
ESP_LOGD(TAG, "need_read=%d, byte_to_read=%d, rlen=%d, ridx=%d", need_read, byte_to_read, rlen, ridx);
11931193

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

0 commit comments

Comments
 (0)