-
Notifications
You must be signed in to change notification settings - Fork 7.6k
HTTPClient https request works the first time, but fails the second time #6561
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
Comments
This seems to be the same issue as #6165. It should work in 2.0.3-rc1 |
Yes, please try to retest it on v2.0.3-rc1. |
Tested it on First calls work as expectedd (just like above) Second call fails with error code -2 BUT the thrid call of that same URL works just fine, it then alternates bewteen 200 and -2 of status codes returned. So; works |
Update: If I do the call every 5 minutes, it breaks, if I do it every 5 seconds, it works just fine... |
Can you track the free heap? See my (still pending) PR for my own project to include TLS support.
These are taken from this lib and adapted to prevent this memory leak as the mbettls context objects are not dealt with properly. |
This was added to our Roadmap, we will investigate it further. Thanks for your contribution. |
A request would work, it s the content that just not right. |
Sorry for the late reply. I have checked memory usage and that didn't seem to be the rpoblem. I even extracted the code into a blank project and tested it the exact same way. Same results. |
Sockets can be reused for multiple requests with HTTP1.1, but 5 minutes is a really long time - is it possible the server is just closing it? You said it works ok at a 5s interval. If your interval is going to be that long, maybe just move the declaration of the httpclient inside the sendHeartBeatApiCall() function? |
OK, found another issue with the HTTPClient on ESP32. Problem is located here: arduino-esp32/libraries/HTTPClient/src/HTTPClient.cpp Lines 372 to 410 in 3f69bcf
When calling By simply calling Not sure if the best fix should be in this IMHO this code should be executed regardless the arduino-esp32/libraries/HTTPClient/src/HTTPClient.cpp Lines 392 to 406 in 3f69bcf
But then there should be an extra check on whether So it should probably something like this (untested) void HTTPClient::disconnect(bool preserveClient)
{
if(connected()) {
if(_client->available() > 0) {
log_d("still data in buffer (%d), clean up.\n", _client->available());
_client->flush();
}
} else {
log_d("tcp is closed\n");
}
if(_reuse && _canReuse) {
log_d("tcp keep open for reuse");
} else {
log_d("tcp stop");
if (_client != nullptr) _client->stop();
if(!preserveClient || _client == nullptr) {
_client = nullptr;
#ifdef HTTPCLIENT_1_1_COMPATIBLE
if(_tcpDeprecated) {
_transportTraits.reset(nullptr);
_tcpDeprecated.reset(nullptr);
}
#endif
}
}
} N.B. the default for |
I had this problem when a first HTTPS request was made using The error I got with that was similar to platformio/platform-espressif32#649:
|
This is corresponding with what I was saying. Good job @TD-er |
I found that |
@RosiersRobin Can this issue be closed? |
@VojtechBartoska I still have this issue. There seems to be no fix yet for this? |
Very annoying issue, and I finally found an explanation here. This suggested workaround does not work for me: #3387 (comment) |
Hello, I close this since this report contains the release we no longer support. Please try the new versions and in case the issue persists, feel free to reopen it. Thanks |
Board
ESP32-Wroom-32UE
Device Description
Plain module un custom hardware with an ETH chip (LAN8720) connected to it, using that chip to cummunicate with internet intead of wifi.
Hardware Configuration
GPIO0 has 50Mhz crystal input for ETH -> disabled on boot, thus device boots
GPIO12 -> crystal power pin
GPIO2 -> I2C clock signal
GPIO17 -> I2C MDIO
Version
v2.0.2
IDE Name
Arduino IDE
Operating System
Windows 10
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
921600
Description
I updated from version 1.0.6 to 2.0.2 and changed nothing to the code. The code works still, however, it seems that the
HTTPClient
is broken since then.I can do an API call to the server once, but not twice.
I have for example a heartbeat that runs every 5 minutes, the first time it runs just fine, the second time I get a -1 error. While this uses the exact same code...
Sketch
Debug Message
All outputs were captured via the serial debug monitor setting the core debug level to verbose.
The text was updated successfully, but these errors were encountered: