ioBroker.admin icon indicating copy to clipboard operation
ioBroker.admin copied to clipboard

port 443 already in use (on another IP adress...)

Open lug-gh opened this issue 3 years ago • 7 comments

You can set the Admin Adapter to a certain IP, but it doesn't seem to check if the port is free on this IP, but if any IP is using port 443.

The admin instance is bound to 10.0.0.10 and there is also an nginx server running on the host which is bound to 10.0.0.11:443.

Thus, the port that the admin instance wants to use is not occupied, but it still complains about this as an error and does not start. I always have to stop nginx first to then be able to start iobroker.

image

This is what it looks like when I start iobroker first, then nginx.

netstat -tuln | grep ':443' 
tcp        0      0 10.0.0.11:443        0.0.0.0:*               LISTEN     (nginx)
tcp        0      0 10.0.0.10:443       0.0.0.0:*               LISTEN	(iobroker)
2022-08-27 11:25:20.922  - error: admin.0 (236362) port 443 already in use
2022-08-27 11:25:20.924  - info: admin.0 (236362) Terminated (ADAPTER_REQUESTED_TERMINATION): port 443 already in use
2022-08-27 11:25:21.441  - info: admin.0 (236362) terminating https server on port 443
2022-08-27 11:25:24.974  - error: host.iobroker instance system.adapter.admin.0 terminated by request of the instance itself and will not be restarted, before user restarts it.

I don't see any logical reason for this, so I think it's a bug when checking port usage.

lug-gh avatar Aug 27 '22 09:08 lug-gh

right, there is no host rovided for the port check ... so providing the settings.bind (if not 0.0.0.0) to https://github.com/ioBroker/ioBroker.admin/blob/master/lib/web.js#L1031 as additional second parameter in that call should fix that ... could you try that out?

Apollon77 avatar Aug 27 '22 20:08 Apollon77

right, there is no host rovided for the port check ... so providing the settings.bind (if not 0.0.0.0) to https://github.com/ioBroker/ioBroker.admin/blob/master/lib/web.js#L1031 as additional second parameter in that call should fix that ... could you try that out?

Sorry, I don't understand what to do, I'm no developer :)

lug-gh avatar Aug 29 '22 07:08 lug-gh

Ok, then for you to try...

  • open /opt/iobroker/node_modules/iobroker.admin/lib/web.js
  • change line 1031 from https://github.com/ioBroker/ioBroker.admin/blob/master/lib/web.js#L1031 to
                    adapter.getPort(settings.port, (!settings.bind || settings.bind === '0.0.0.0') ? undefined : settings.bind || undefined, port => {

The line number above refers to the very latest Beta Admin version, so check the content please

Restart admin, try again

Apollon77 avatar Aug 29 '22 07:08 Apollon77

Thanks! Looks good, if the port is not used I can start the admin adapter, and if it's occupied I cannot.

lug-gh avatar Aug 29 '22 07:08 lug-gh

Ok,then I will bring this in a next update

Apollon77 avatar Aug 29 '22 08:08 Apollon77

Other adapters that could benefit:

ioBroker.contact/main.js: adapter.getPort(settings.port, (port) => { ioBroker.egigeozone/main.js: adapter.getPort(settings.port, function (port) { ioBroker.geofency/main.js: adapter.getPort(settings.port, port => { ioBroker.harmony/harmony.js: adapter.getPort(61991, port => { ioBroker.lovelace/main.js: adapter.getPort(server.settings.port, port => { ioBroker.megad/main.js: adapter.getPort(adapter.config.port, function (port) { ioBroker.megadd/main.js: adapter.getPort(adapter.config.port, function (port) { ioBroker.megaesp/main.js: adapter.getPort(adapter.config.port, function (port) { ioBroker.simple-api/main.js: adapter.getPort(settings.port, port => { ioBroker.socketio/main.js: adapter.getPort(settings.port, async port => { ioBroker.swagger/main.js: adapter.getPort(settings.port, port => { ioBroker.telegram/main.js: adapter.getPort(adapter.config.port, port => { ioBroker.template-rest/main.js: adapter.getPort(settings.port, function (port) { ioBroker.web/main.js: adapter.getPort(settings.port, port => { ioBroker.wetty/main.js: adapter.getPort(settings.port, function (port) { ioBroker.xterm/main.js: adapter.getPort(settings.port, async port => { iobroker.paw/main.js: adapter.getPort(adapter.config.port, function (port) { iobroker.terminal/main.js: adapter.getPort(settings.port, function (port) { ioBroker.admin/lib/web.js: adapter.getPort(settings.port, port => { ioBroker.tronwallets/lib/web.js: adapter.getPort(settings.port, port => {

Apollon77 avatar Aug 29 '22 08:08 Apollon77

Awesome!

Apollon77 avatar Aug 29 '22 16:08 Apollon77

Well, for me it seems to break the iobroker.admin instance after reboot.

iobroker status admin.0

Instance "admin.0" is running

So i create a dummy log entry to be sure where the log starts before the reboot echo "########## DUMMY NACHRICHT admin.0 - ab hier wenn port 443 beim boot NICHT belegt ist" >> /opt/iobroker/log/iobroker.current.log && reboot

wait for the reboot to be done

grep 'admin.0' /opt/iobroker/log/iobroker.current.log

########## DUMMY NACHRICHT admin.0 - ab hier wenn port 443 beim boot NICHT belegt ist
2022-11-24 20:33:15.362  - info: admin.0 (3426) terminating https server on port 443
2022-11-24 20:33:15.423  - info: host.rpi4 stopInstance system.adapter.admin.0 (force=false, process=true)
2022-11-24 20:33:15.641  - info: admin.0 (3426) Got terminate signal TERMINATE_YOURSELF
2022-11-24 20:33:15.701  - info: host.rpi4 stopInstance system.adapter.admin.0 send kill signal
2022-11-24 20:33:15.716  - info: admin.0 (3426) Terminated (START_IMMEDIATELY_AFTER_STOP): Without reason
2022-11-24 20:33:16.820  - info: host.rpi4 stopInstance system.adapter.admin.0 killing pid 3426
2022-11-24 20:33:17.399  - warn: host.rpi4 instance system.adapter.admin.0 terminated due to SIGTERM
2022-11-24 20:33:17.399  - info: host.rpi4 instance system.adapter.admin.0 terminated with code null ()
2022-11-24 20:33:31.969  - info: host.rpi4 instance system.adapter.admin.0 started with pid 633
2022-11-24 20:33:33.866  - info: admin.0 (633) starting. Version 6.2.23 in /opt/iobroker/node_modules/iobroker.admin, node: v14.19.3, js-controller: 4.0.23
2022-11-24 20:33:33.972  - warn: admin.0 (633) Cannot check node.js versions: Error: getaddrinfo EAI_AGAIN nodejs.org
2022-11-24 20:33:33.983  - warn: admin.0 (633) Cannot update news: getaddrinfo EAI_AGAIN iobroker.live
2022-11-24 20:33:33.992  - info: admin.0 (633) requesting all states
2022-11-24 20:33:33.992  - info: admin.0 (633) requesting all objects
2022-11-24 20:33:34.392  - info: admin.0 (633) Request actual repository...
2022-11-24 20:33:34.773  - info: admin.0 (633) received all objects
2022-11-24 20:33:35.715  - info: admin.0 (633) Repository received successfully.
2022-11-24 20:33:40.777  - error: admin.0 (633) port 443 already in use
2022-11-24 20:33:40.779  - info: admin.0 (633) Terminated (ADAPTER_REQUESTED_TERMINATION): port 443 already in use
2022-11-24 20:33:41.304  - info: admin.0 (633) terminating https server on port 443
2022-11-24 20:33:41.363  - error: host.rpi4 instance system.adapter.admin.0 terminated by request of the instance itself and will not be restarted, before user restarts it.
2022-11-24 20:33:41.364  - info: host.rpi4 Do not restart adapter system.adapter.admin.0 because desired by instance

and this, even if port 443 is not used!

netstat -tulpn | grep ':443:' no output, to verify: echo $?

1

to get the adapter up i have to execute this after the boot: iobroker stop admin.0 && iobroker start admin.0

The adapter "admin.0" was stopped.
The adapter "admin.0" was started.

iobroker status admin.0

Instance "admin.0" is running

lug-gh avatar Nov 24 '22 19:11 lug-gh

If this error comes then the adapter can not bind the server to port 443 ... please try to run "iob fix" to fx pot permission issues.

Additionally: getaddrinfo EAI_AGAIN means that there are DNS issues!!

Apollon77 avatar Nov 24 '22 21:11 Apollon77

please try to run "iob fix" to fx pot permission issues

Unfortunately iob fix didn't help to fix it

there are DNS issues!!

Hmm, so my DNS server logs all requests, and all requests from my Pi were answered successfully, strange.

      Also, I'm not sure if this issue is related to this github-issue, or would that be better handled separately?

lug-gh avatar Nov 29 '22 17:11 lug-gh

@foxriver76 the issue is still existent

lug-gh avatar Aug 06 '23 20:08 lug-gh

extended debugging

Strange, did some more testing, even if the port 443 is not used by any other process - after a reboot of my raspberry pi, the adapter fails to start.

2023-08-10 21:20:51.956  - info: host.rpi4 instance system.adapter.admin.0 started with pid 583
2023-08-10 21:20:54.285  - info: admin.0 (583) starting. Version 6.3.5 in /opt/iobroker/node_modules/iobroker.admin, node: v18.17.1, js-controller: 4.0.24
2023-08-10 21:20:54.464  - warn: admin.0 (583) Cannot check node.js versions: Error: getaddrinfo EAI_AGAIN nodejs.org
2023-08-10 21:20:54.486  - warn: admin.0 (583) Cannot update news: getaddrinfo EAI_AGAIN iobroker.live
2023-08-10 21:20:54.495  - info: admin.0 (583) requesting all states
2023-08-10 21:20:54.497  - info: admin.0 (583) requesting all objects
2023-08-10 21:20:55.079  - info: admin.0 (583) Request actual repository...
2023-08-10 21:20:55.564  - info: admin.0 (583) received all objects
2023-08-10 21:20:56.728  - info: admin.0 (583) Repository received successfully.
2023-08-10 21:21:02.878  - error: admin.0 (583) port 443 already in use
2023-08-10 21:21:02.880  - info: admin.0 (583) Terminated (ADAPTER_REQUESTED_TERMINATION): port 443 already in use
2023-08-10 21:21:03.439  - info: admin.0 (583) terminating https server on port 443
2023-08-10 21:21:03.508  - error: host.rpi4 instance system.adapter.admin.0 terminated by request of the instance itself and will not be restarted, before user restarts it.
2023-08-10 21:21:03.509  - info: host.rpi4 Do not restart adapter system.adapter.admin.0 because desired by instance

I see the getaddrinfo Errors, but I cannot see a reason why that happens.

root@rpi4:~# nslookup nodejs.org
Server:         192.168.1.1
Address:        192.168.1.1#53

Non-authoritative answer:
Name:   nodejs.org
Address: 104.20.22.46
Name:   nodejs.org
Address: 104.20.23.46
Name:   nodejs.org
Address: 2606:4700:10::6814:162e
Name:   nodejs.org
Address: 2606:4700:10::6814:172e
root@rpi4:~# nslookup iobroker.live
Server:         192.168.1.1
Address:        192.168.1.1#53

Non-authoritative answer:
Name:   iobroker.live
Address: 217.160.0.211
Name:   iobroker.live
Address: 2001:8d8:100f:f000::2ca

Edit: to ensure these errors are not by dns, I added the dns records to /etc/hosts, then I dont get getaddrinfo errors, but

2023-08-10 21:43:03.749  - warn: admin.0 (584) Cannot check node.js versions: Error: connect ENETUNREACH 104.20.23.46:443 - Local (0.0.0.0:0)
2023-08-10 21:43:03.767  - warn: admin.0 (584) Cannot update news: connect ENETUNREACH 217.160.0.211:443 - Local (0.0.0.0:0)

So, iobroker want's to start before network is up?

Edit 2: Okay, it seems like the raspberrypi is the issue - well - more or less. If I disable the autostart (systemd service file), reboot the pi, and go to htop, I see a 100% CPU load for 2-3 minutes. After that drops to <10% I manually start iobroker, and that's it. So the load at boot is the issue.

lug-gh avatar Aug 10 '23 19:08 lug-gh

❓ But, why am I getting that error message with the port already being used? Is this message displayed if the check for update/nodejs version fails, or because the check if the port is already in use runs into a timeout?

lug-gh avatar Aug 10 '23 20:08 lug-gh

I just updated from 6.4.4 to 6.8.0.

Kills admin with these messages in the log:

2023-09-03 08:11:51.288  - error: admin.0 (11549) port 443 already in use
2023-09-03 08:11:51.291  - info: admin.0 (11549) Terminated (ADAPTER_REQUESTED_TERMINATION): port 443 already in use
2023-09-03 08:11:51.828  - info: admin.0 (11549) terminating https server on port 443
2023-09-03 08:11:52.023  - info: host.pl instance system.adapter.admin.0 terminated by request of the instance itself and will not be restarted, before user restarts it.
2023-09-03 08:11:52.025  - info: host.pl Do not restart adapter system.adapter.admin.0 because desired by instance

netstat shows no processes using 443:

$ netstat -anp | grep LISTEN | grep 443

Strangely iob start admin.0 does nothing. But restart does at least try and start the instance:

$ iob start admin.0
$ iob restart admin.0
The adapter "admin.0" was started.

However, it dies again:

2023-09-03 08:20:30.641  - info: host.pl instance system.adapter.admin.0 started with pid 15280
2023-09-03 08:20:35.445  - info: admin.0 (15280) starting. Version 6.8.0 in /opt/iobroker/node_modules/iobroker.admin, node: v16.20.2, js-controller: 5.0.8
2023-09-03 08:20:35.516  - info: admin.0 (15280) requesting all states
2023-09-03 08:20:35.518  - info: admin.0 (15280) requesting all objects
2023-09-03 08:20:37.445  - info: admin.0 (15280) received all objects
2023-09-03 08:20:37.931  - info: admin.0 (15280) Request actual repository...
2023-09-03 08:20:38.772  - info: host.pl Updating repository "Stable (default)" under "http://download.iobroker.net/sources-dist.json"
2023-09-03 08:20:40.761  - info: admin.0 (15280) Repository received successfully.
2023-09-03 08:21:37.080  - error: admin.0 (15280) port 443 already in use
2023-09-03 08:21:37.083  - info: admin.0 (15280) Terminated (ADAPTER_REQUESTED_TERMINATION): port 443 already in use
2023-09-03 08:21:37.607  - info: admin.0 (15280) terminating https server on port 443
2023-09-03 08:21:37.734  - info: host.pl instance system.adapter.admin.0 terminated by request of the instance itself and will not be restarted, before user restarts it.
2023-09-03 08:21:37.735  - info: host.pl Do not restart adapter system.adapter.admin.0 because desired by instance

netstat again shows no processes using 443:

$ netstat -anp | grep LISTEN | grep 443

This is a major bug!

raintonr avatar Sep 03 '23 06:09 raintonr

Please run "iob fix". Still happens? Also with newest beta version?

Apollon77 avatar Sep 03 '23 06:09 Apollon77

Please run "iob fix". Still happens? Also with newest beta version?

iob fix solved this scenario for me. No beta (see version number in log above).

raintonr avatar Sep 03 '23 07:09 raintonr

@raintonr Just for Info: According to log js-controller: 5.0.8. This is beta and not the newest beta :-). But likely not related to this issue

mcm1957 avatar Sep 03 '23 09:09 mcm1957

@Apollon77 should I create a new issue? It is clear that under certain circumstances, an incorrect or misleading error message is displayed. A generic error message is better than a misleading message, right?

lug-gh avatar Sep 04 '23 08:09 lug-gh

Yes a new issue fpr better error mesagwer would be cool ... or a PR :-)

Apollon77 avatar Sep 06 '23 15:09 Apollon77