ioBroker / ioBroker.mqtt

Mqtt server and client for ioBroker.
MIT License
54 stars 29 forks source link

Client error:Error: getaddrinfo ENOTFOUND admin #275

Closed miriki closed 2 years ago

miriki commented 2 years ago

Describe the bug
The MQTT adapter can't connect to localhost after update to 2.7.4 (from 2.6.1 methinks, but not sure).

To Reproduce
I tried (via Putty SSH)

iob stop all
iob stop
sudo reboot
...
iob start
iob start admin
iob start mqtt

And I get in the log:

mqtt.0              2022-04-17 14:15:52.762 info    Adapter is disabled => stop

mqtt.0              2022-04-17 14:15:42.981 info    Disconnected from localhost
mqtt.0              2022-04-17 14:15:42.979 error   Client error:Error: getaddrinfo ENOTFOUND admin
mqtt.0              2022-04-17 14:15:42.967 info    Reconnected to localhost
mqtt.0              2022-04-17 14:15:32.960 info    Disconnected from localhost
mqtt.0              2022-04-17 14:15:32.958 error   Client error:Error: getaddrinfo ENOTFOUND admin
mqtt.0              2022-04-17 14:15:32.946 info    Reconnected to localhost
mqtt.0              2022-04-17 14:15:22.938 info    Disconnected from localhost
mqtt.0              2022-04-17 14:15:22.936 error   Client error:Error: getaddrinfo ENOTFOUND admin
mqtt.0              2022-04-17 14:15:22.917 info    Reconnected to localhost
mqtt.0              2022-04-17 14:15:12.903 error   Client error:Error: getaddrinfo ENOTFOUND admin

mqtt.0              2022-04-17 14:15:12.471 info    Try to connect to mqtt://Admin:*******************@localhost:1883?clientId=iobroker.mqtt.0
mqtt.0              2022-04-17 14:15:11.728 info    starting. Version 2.7.4 in /opt/iobroker/node_modules/iobroker.mqtt, node: v12.22.10, js-controller: 4.0.21

The ENOTFOUND repeats every second until the instance is stopped.

Expected behavior
The adapter connected 2 days ago, before I updated this and some other adapters via the adapters view page of iobroker. I already downgraded to 2.6.1, but the error persists. The other adapters like Node-Red, OctoPrint, Vis etc. don't seem to have any problems.

Screenshots & Logfiles
see log above

Versions:

Additional context
ioBroker is running on a RasPi 3b+ with Debian 11 (bullseye) as 192.168.1.150 (WLAN) and 151 (LAN). localhost is 127.0.0.1 in /etc/hosts plus an additional entry iobrokerpi with 127.0.1.1

Apollon77 commented 2 years ago

Please show the configuration ... he tries to do an DNS lookup for "admin" which then fails...

miriki commented 2 years ago

I just tried it 2 times with a fresh install of the whole PI. 1st attempt with (usually by me) needed adapters, right now the 2nd attempt with only the mqtt adapter. The problem persists, ENOTFOUND every second. Which conf. would you like to see? The adapter instance? Here it goes: Typ: Client/Subscriber URL: localhost Port: 1883 [ ] SSL [X] rejectUnauthorized Benutzer: Admin Kennwort: **** Passwort-Wiederholung: **** Die Verbindung zum Server testen --> Ergebnis: error

If I switch to server mode: Typ: Server/Broker [ ] Websockets benutzen IP Adresse: [IPv4] 0.0.0.0 - Listen on all IPs Port: 1883 [ ] SSL [X] rejectUnauthorized Benutzer: Admin Kennwort: **** Passwort-Wiederholung: ****

Obviously there's no "test" button. The instance starts without errors in the log and shows (unfolded) in the instances' page: [X] Verbunden mit Host [X] Lebenszeichen [ ] Verbindung: - = same as in client mode.

The "admin"... Is it looking for a user with this name? Or an adapter? or what? The PI is named "iobrokerpi" (right now "raspberrypi") with a user "pi". Which "admin" should be in any DNS?

miriki commented 2 years ago

add.: Using 127.0.0.1 instead of localhost doesn't fix it either Try to connect to mqtt://Admin:*******************@127.0.0.1:1883?clientId=iobroker.mqtt.0 still gets Client error:Error: getaddrinfo ENOTFOUND admin

And when / where is "Admin" changed to lowercase "admin"?

add. 2: I just tried to set the username to "127.0.0.1" to see what happens: Client error:Error: connect ECONNREFUSED 127.0.0.1:1883 So the user:Admin Password:**** seems to be used and accepted, if there won't be the ENOTFOUND error. (thought it might use the user:Admin instead of the URL:localhost for the URL lookup.)

Apollon77 commented 2 years ago

What characters the password consists of?

Apollon77 commented 2 years ago

I would have the assumption that a special character in your password could confuse the url parser from the mqtt library

miriki commented 2 years ago

8 characters with uppercase, lowercase, digits and special '#' in it. I try to avoid '@' and '.' in passwords.

Apollon77 commented 2 years ago

Can you try to get rid of the "#" and see if it works then?

Apollon77 commented 2 years ago

PS: Yes I verified it ... the # character is the issue, it breaks the URL parsing

Apollon77 commented 2 years ago

Ok, wait ... I try to get a fix for you

Apollon77 commented 2 years ago

Please install GitHub version and try it ...

Please Note that it is a major upügrade in your case when coming from 2.x so you NEED TO reener the password in the adapter settings!!

miriki commented 2 years ago

Hmmm... I still get the error. I tried:

iob del mqtt
iob add mqtt@3.0.5

Settings with the # password re-entered, verified with the 'eye' to reveal the typed characters.

Then I tried: iob passwd admin Using a password with only a digit and lowercase letters. Using that new password now I get a Client error:Error: connect ECONNREFUSED 127.0.0.1:1883 even after a reboot of the PI.

I actually set it back to the # password and reboot the PI. Still trying...

Apollon77 commented 2 years ago

I said that you shpulkd install the GitHub version please, not 3.0.5 :-)

Admin - enable expert mode - Adapter page - github icon - "Install from gitHub" tab - choose mqtt

miriki commented 2 years ago

Ok, I misunderstood that. I've never used that way before. Is it normal behaviour that there is no instance created by installing the adapter? I had to "iob add mqtt" to create one after the install. The adapter page showed 3.0.5 vs. 2.7.4 versions.

Ok, the error ECONNREFUSED is replacing the old ENOTFOUND. I tried combinations of "Admin" and "admin", old password with # and new one without, changing password to new and back to old via "iob passwd admin", rebooting, ...

I will set up another fresh install of the SD card and will use a password without # any more. Are there any other characters that might lead to problems?

miriki commented 2 years ago

Ok, the "old" pi installation (the one I actually removed the SD card after the problems after update) seems to have the same ECONNREFUSED problem. I tried iob del mqtt and then installed via github from the adapter page as you said. After that iob add mqtt gave me the mqtt.0 instance. Configured with the above settings and... ECONNREFUSED. Btw, the used password is "kind of" Kp29#2Fl Maybe that helps in finding the problem, position of the # or whatever may cause it.

Apollon77 commented 2 years ago

1.) ECONNREFUSED means that the network connection got refused. Check the MQTT server you want to connect to.

2.) Yes installations from GitHub are never creating an instance automatically (and in fact I never told to uninstall adapter first ;-))) You can simply install over it and existing instances are still there.

Apollon77 commented 2 years ago

PS: Ok to make sure it is not the server you can try to change the password to not include the # ... if it works then, then it seems to be caused by my change :-( and in fact (now saw) then it would mean the password is sent wrong :-( Then I ned to look deeper

Apollon77 commented 2 years ago

PPS: Ok I now changed some things more and also adjusted the tests to verify it works. SO please update from GitHub again ... does it work now?

miriki commented 2 years ago

I had to struggle a bit with the PI. While switching the SD cards back and forth something broke the connection to the 7" display (or the display itself) giving only a black screen any more. Additionally the power adapter actually produces "under-voltage" warnings and a powered USB hub and a Samsung charging plug do the same. Nevertheless, ignoring the under-voltage warnings on the 24" monitor every 30 seconds or so, I configure and test mainly via SSH and browser.

Now I am using a password in the form of Ab12Cd34 and this seems to work.

While testing configs and adapters I stumbled across... erm.. well... The story began after the adapter updates when I found the "ENOTFOUND" in the logs. But... Looking back I have to ask: Why does the adapter try to connect anywhere? It should be a server waiting to get connected by clients. So somewhere in the past, by the updates or any other situation, the mqtt adapter mode was switched from server to client. In fact I had used the client mode (a bit experimenting) in the past, but that is some long time ago. Sorry me not recognizing that situation.

But: I tried the client mode connecting to an experimental server on a win10 machine and it works, too. I don't get any ENOTFOUND or ECONNREFUSED any more. Ok, it's not 'localhost' or any other named address, but using the IP 192.168.1.165 directly. I have to test it with a name for a DNS (Fritz-Box' .local or the like).

Switching back to server mode it is happily connected by a self-made Tasmota (soil moisture) device and node-red shows the received values with a gauge.

So the server mode may or may not function with 2.7.4 version. Your actual modification in the 3.0.5 definitely did the trick for the client mode. I'll stick with that version. I just have to check with passwords and special characters in client mode the next days. Stay tuned but don't hold your breath. ;-)

Apollon77 commented 2 years ago

Ok, I think because also tests are green I will release later today.

BTW: In fact the error was that the password was not encoded correctly ... so maybe when you have isues with such passwords on server side check your client implementatuons ... maybe they also do nt encode it correctly ... or just do not use a hash in the password :-)

Apollon77 commented 2 years ago

Will be in next version

m50434 commented 2 years ago

Hi, I had the same error "getaddrinfo ENOTFOUND".

I installed the current version from github (3.0.6). It didint help!

Then I changed the password: I had ! and ? inside. Without these "special characters" it is working!

Apollon77 commented 2 years ago

I adjusted the tests to also use ! and ? and it works without issues ... sure that 3.0.6 (which is no longer Github) was installed correctly?

m50434 commented 2 years ago

I htink so. I installed 3.0.6 through github-url

grafik

Apollon77 commented 2 years ago

Strange, ass aid ... test succedd even with such characters in the password