-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Getting [E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
randomly
#2778
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
[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
after ESP restart[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
after ESP crash
[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
after ESP crash[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
random
[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
random[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed
randomly
can you confirm the value of URL is valid at all times? It may make sense to add a log output to print the URL being attempted. |
URL starts as follows: First condition comes from HTML: Second condition comes from the web-server: Third condition is the one in
I have tried with the same URL over and over again. I sometimes get the error and sometimes it works perfectly.
I don't follow. My
|
What I meant was can you add a printf (or Serial.println in your case likely) to dump the URL value just before you call http.begin(URL); I suspect that you are ending up with a partial value in the URL string that is causing the DNS failure. |
I've added:
For now it seems that it works. |
@atanisoft
My workaround is to have a counter each time
What do you think causes |
That means it failed to resolve the hostname. There are a number of reasons for this and usually a retry should fix it. |
You should also check the return value from http.begin() as it should return false when dns fails. |
Ok. I will further investigate using this: My concern is that the DNS fails only after a crash. |
@atanisoft
And then comes Do you have any idea why is this happening ? |
Unfortunately I'm not sure why it is doing that |
I have same this bug. and now i use counter to check dns fail if over 6 times i use i think fix this bug without restart ESP is better. |
I can confirm this issue, as I have been investigating the same problem for a couple of weeks now. These are my observations: Devices and Configuration ESP32 Dev Module Error Logged [E][WiFiGeneric.cpp:652] hostByName(): DNS Failed for m20.cloudmqtt.com Behaviour Once the ESP32 has connected to WiFi and MQTT client is connected, the code runs tasks that read sensors and other typical microcontroller tasks. I usually have the MQTT web interface open so I can see messages going in and out of the ESP32. Now the dns failure can happen randomly. And sometimes hours or even just a few minutes after the device has been powered up or reset. WiFi Stack Game Over However, once it has failed it will not recover. I had to implement a similar regime as @maxpromer and do an ESP.restart() after a set number of failures. I tried reconnecting WiFi client but this issue seems to break the WiFi stack and only a reset will get it working. Host is online, DNS resolution is fine When it is in this DNS failed state, I can nslookup the domain from my PC and the MQTT web interface is working fine. This issue affects the fundamental operation of an IOT device - it must be able to maintain its connection to the WiFi AP so that it can access resources such as MQTT brokers, http APIs and so forth. I now make the assumption that the internet is down when I implement my code, as the WiFi stack is not reliable enough to maintain a connection or recover from outages and failed DNS resolution. Proposed Change It seems it would be safer to assume that once DNS has been resolved, that the resolved IP address could be cached. The IP address for mqtt.com, for example, has not changed in over a year. The DNS failure could raise a callback, that would pass the last successfully resolved IP address and the developer could then attempt to connection using the LastSuccessfulIPAddress, instead of the host name. If this fails to connect then, a few retries of the same patterns and we could assume with some certainty that the host may well be offline or unavailable. ESP8266 By Comparison I have a couple of ESP8266 running the same MQTT client and they been online for 18 months now and I have never had to reset them, not even once. They have survived internet outages, MQTT outages, simply I assume because the WiFi stack recovers from these issues and keeps a healthy connection. |
Hi, may be my experience can shed some light at the DNS mistery as I myself was also struck by the infamous: "[E][WiFiGeneric.cpp:652] hostByName(): DNS Failed...blá, blá ,blá" My code was running rock solid for months in a ESP32 Heltec LoRa board using WiFi+MQTTS+TLS=> Mosquitto Server. After hours of debugging I found out the culprit, a invalid IP string being converted by IPAddress.formString(). The boolean result was not checked in code and the bad IPAddress result was used in a WiFi.softAPConfig() setup. After that line the WiFi stack started to pop all sort of random errors including DNS and SSL failures. Fixed the invalid string and a we are back on heaven again. Hope it might help. |
If you are facing this issue can you once try restarting WIFI router and confirm please.. |
It is always the ESP32 that has to be restarted - router restart does not help, as the WiFi never recovers the connection after the DNS error message. |
Thank you for the suggestion. I'll look through the code - always worth checking with things like this. I'm still bothered by the fact that the device cannot recover from this situation. For an IOT device, this is a disaster as it will not recover and be offline. If remotely deployed, then this is even more of an issue. |
Hello. I am having the same problem. By some reason, the call http.begin("web address"); gives the infamous error and causes the ESP32 to crash. I have implemented the counter for resetting the device, but it does solve the problem in all cases. I still have my device frozen from time to time (once a day maybe, device connecting to the AP and sending the data once per minute). It is true that now this happens more rarely. If I think that I have to place tens of devices in remote locations, I get a bit concerned. |
This is really bad. I check the server for online requests every ten seconds. After a few minutes of continuous requests, the server disconnects and then connects again. It will also return DNS Failed for xxxxx. Very badly, every few Need to restart once in minutes |
This is not a fix. But what I do is reconnect. |
Anyone from the Espressif team that could at least give an opinion on this? With almost 1000 issues on this project, prioritizing is obviously a challenge. However, I would say that any issue that concerns WiFi is worthy of some attention. It is after all the basis of IOT capability. |
I saw what you said compared to 8266. I put the code running on on 8266. It works fine, although it will also be offline from the server, but it works fine again, instead of needing to restart. |
I am also getting this problem on ESP32 when the code works perfectly on ESP8266. I get: |
I am connecting to the same server in the esp-idf framework, it works fine, so this is definitely a problem with arduino-esp32, I have to run the code in esp-idf because it is stable |
IDF has a few bug fixes which have not made it over to the arduino-esp32 side likely. |
I'm seeing the same problem. Once it starts failing it will not recover and must be restarted. Debug output looks like this:
There is no corruption in the URL and anything that uses HTTPClient, including HTTPUpdate, fails once this starts occurring. The only solution is to restart.
High water mark for the main loop is 5048 and freeHeap is 200K+. Oddly, if I compile with debug/verbose output it runs much longer before failing, but does start failing eventually. And it fails the same way in both 1.02 and 1.03RC. |
Hello to all, [HTTP] begin... I suspect thar can be a driver problem in the drivers or IDE. Thanks |
Hello guys, The ESP32 turn me into trouble when I try to connect to myHost with the WifiClient.
But the point is, if I connect the WifiClient to the host: data.sparkfun.com with the port 80 everything works well. I also tried to set the wifi-settings manually, but the same result: sparkfun works, myHost not.
Do you have any suggestions what I can do? Thank you in advance! |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
I had similar problem using VPN connection.
If the answer from DNS server is very slow and sometimes it takes over 4000ms, WIFI_DNS_DONE_BIT is set by callback after this timeout and remains set. In the next DNS ask, function waitStatusBits() exits immediatelly because this bit is set, aResult is zero so function returns 0 (error) and then http.GET() returns error -1 (connection refused). |
Please could this issue be re-opened - it does not appear to be resolved. |
I also postulate that this issue should be re-opened.
use the parameter srv (internally aResult) as variable declared on stack (or heap?). |
Hi, Unfortunatelly there are many reasons, why "start_ssl_client", which is called by WiFiClientSecure::connect returns -1, and in my case it was because Test case: Wifi connection droped, after it was established again, asier70's proposal did the fix:
The only thing, which I'm still wondering, that Stack Watermark is stressed a lot during my tests.
Could you explain a little more, please? And yes, you are right, this issue should be reopened.... BR, |
Sorry for my late answer.
At file ssl_client.cpp it looks similiar:
Object srv is local and placed on stack (temporary object of IPAddress class). pointer to this object is passed to hostByName() function and then it is used by DNS callback function. Function hostByName() waits only 4 seconds if DNS operation is in progress. If DNS operation lasts more time it returns with error but internal DNS operation still works and at the end callback function is called. Callback function still has pointer to object srv that doesn't exists at this moment, so it writes resolved IP address to this memory area. Probably this stack memory area is already used by other function so this can have unknown consequences to application work :( |
This thread is closed so I decided to open new issue #3722 to show that this problem exists and should be solved. |
Thanks for opening a new issue. |
Hello !
I am using a HTTP Client inside loop to check for the body of a URL.
It worked fine until it didn't.
Today the ESP crashed and restarted. After the restart it connected to the WiFi using SSID and Password, so using DHCP. But it behaved like it did not connect.
This is a part of the code that runs in
void loop()
:Manually restarting the ESP, by pressing on the EN button, did fix the issue, however I still get this randomly. The only fix is to restart again !
The text was updated successfully, but these errors were encountered: