Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing HTTPS sockets returns ESP_FAIL - due to two lwip_close calls (IDFGH-4321) #6163

Closed
ghost opened this issue Nov 25, 2020 · 2 comments
Closed

Comments

@ghost
Copy link

ghost commented Nov 25, 2020

Environment

  • IDF version:
    v4.3-dev-1721-g9bcf8ad19
  • Compiler version:
    xtensa-esp32-elf-gcc (crosstool-NG esp-2020r3) 8.4.0

Problem Description

A call to esp_http_client_close - after opening a connection to a HTTPS server - results in ESP_FAIL & errno being set to 9, which is Bad file number.
I've tracked the issue to lwip_close being indirectly called twice in

int esp_tls_conn_destroy(esp_tls_t *tls)
{
if (tls != NULL) {
int ret = 0;
_esp_tls_conn_delete(tls);
if (tls->sockfd >= 0) {
ret = close(tls->sockfd);
}
esp_tls_internal_event_tracker_destroy(tls->error_handle);
free(tls);
return ret;
}
return -1; // invalid argument
}

Once through

_esp_tls_conn_delete(tls);
and again directly
ret = close(tls->sockfd);

What is the correct course of action here? I'd suggest completely removing the call to close in esp_tls_conn_destroy (L109) as _esp_tls_conn_delete already calls the same function with the same parameter. Or, if it's there for the offchance that tls->is_tls is false, I'd change the if statement (L108) to if (tls->sockfd >= 0 && !tls->is_tls).

Debug Logs

// call to esp_http_client_close
D (36796) TRANS_SSL: [ssl_close(0x3ffca0a8)]
D (36806) esp-tls: [esp_tls_conn_destroy(0x3ffcb510)]

// call to _esp_tls_conn_delete(tls)
D (36806) esp-tls-mbedtls: [esp_mbedtls_conn_delete(0x3ffcb510)]:
sockets.c: [lwip_close(54)]
sockets.c: [lwip_close]: socket=0x3ffb4a54

D (36826) esp-tls: [esp_tls_conn_destroy] errno=0
D (36826) esp-tls: [esp_tls_conn_destroy] tls->sockfd=54

// call to close(tls->sockfd)
sockets.c: [lwip_close(54)]
sockets.c: [lwip_close]: socket=0x0

D (36846) esp-tls: [esp_tls_conn_destroy] errno=9
D (36846) esp-tls: [esp_tls_conn_destroy] ret=-1
@github-actions github-actions bot changed the title Closing HTTPS sockets returns ESP_FAIL - due to two lwip_close calls Closing HTTPS sockets returns ESP_FAIL - due to two lwip_close calls (IDFGH-4321) Nov 25, 2020
@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting, we will look into.

@AdityaHPatwardhan
Copy link
Collaborator

@istokm Thank you for reporting the issue and also suggesting the fix, the fix has already been merged internally. Should be updated on github in a couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants