MQTT Server appears to startup and bind to port specified for MQTT client use
Closed this issue · 4 comments
I am running ApacheMQ on the same host as Polyglot, as I want to use that broker instead of the builtin.
I read these configuration overrides as parameters for the Polyglot MQTT client: specifying a different IP and port combination to connect to instead of the builtin MQTT broker which will come up on port 1883.
https://github.com/UniversalDevicesInc/polyglot-v2/blame/master/README.md#L178-L182
Unfortunately, when I use the parameters to specify 127.0.0.1:1884 polyglot fails to start with this exception:
1/19/2019, 9:29:27 AM - info: Starting Polyglot....
1/19/2019, 9:29:27 AM - info: Settings: Polyglot Version 2.2.1
1/19/2019, 9:29:27 AM - info: Settings: Features {"noticeByKey":"on","customParamsDoc":"on","typedParams":"on"}
1/19/2019, 9:29:27 AM - info: Settings: Retrieved config from database
1/19/2019, 9:29:27 AM - info: Settings: Retrieved config overrides from .env and updated database
1/19/2019, 9:29:27 AM - error: uncaughtException: listen EADDRINUSE :::1884 date=Sat Jan 19 2019 09:29:27 GMT-0600 (Central Standard Time), pid=8104, uid=0, gid=0, cwd=/root/polyglot, execPath=/root/polyglot/polyglot-v2-linux-x64, version=v10.4.1, argv=[/root/polyglot/polyglot-v2-linux-x64, /snapshot/udi-polyglotv2/bin/polyglot-v2.js], rss=98676736, heapTotal=69513216, heapUsed=32630992, external=18010441, loadavg=[0.36328125, 0.111328125, 0.02978515625], uptime=27774
Error: listen EADDRINUSE :::1884
at Server.setupListenHandle [as _listen2] (net.js:1327:14)
at listenInCluster (net.js:1375:12)
at Server.listen (net.js:1462:7)
at /snapshot/udi-polyglotv2/lib/services/mqtts.js:134:27
at new Promise (<anonymous>)
at Object.start (/snapshot/udi-polyglotv2/lib/services/mqtts.js:131:15)
at start (/snapshot/udi-polyglotv2/bin/polyglot-v2.js:76:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
The port conflict is legitimate, I have Apache MQ listening on port 1884 for MQTT. However, it was not my intent to reconfigure the Polyglot MQTT server to listen on port 1884, only have the client connect to that port.
If it were possible to prevent the startup of Polyglot's MQTT server with a separate override, I think this issue would be resolved.
Note: this is my first MQTT foray: if the protocol dictates that clients have their own TCP listener on the same port as the server this is a conflict with that protocol and not a Polyglot issue.
Oh dear, even worse when I deleted the overrides from .env
the MQTT server is still binding to 1884 even though the client is now back to looking for it on the default of 1883.
I'm going to see if I can use this to hack it into doing what I want.
Yeah, because of this I can now configure my Apache MQ to listen on port 1883 and the Polyglot MQTT client will try to connect to it.
Have to set this down for now, but will report later if this is an effective workaround.
The temporary behavior of client and server using different ports seems to have been transient. I figured out the built-in server doesn't support websockets, dialed in with mosquito_sub
and determined the event stream wasn't what I was looking for.
I'm not impacted by this behavior, but it still looks like an opportunity to me.