-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
When connecting ws://[::1]:8883
, an error is thrown - Uncaught TypeError TypeError [ERR_INVALID_URL]: Invalid URL
#1569
Comments
Might be relevant: nodejs/node#44731 |
@mklinke no, I dont think so. I strongly believe this is a bug in how this lib (MQTT.js) breaks down and re-assembles the URL as detailed in my initial post:
|
Could you submit a PR to fix this? |
MQTT 5.0.0 BETA is now available! Try it out and give us feedback: |
While testing using a severs ipv6 address, I've noticed this issue. I construct a websocket url using window.location.hostname, when the error is thrown the URL is missing brackets. IPv6 connections using a name work properly, just not bracket notation. Using 5.5.0 |
same question.. when my url be mqtts://::1:14509 it cant be working , but i change to mqtts://127.0.0.1:14509 it work |
Can anyone submit a PR to fix this issue? I think it's just a matter of url parsing here: MQTT.js/src/lib/connect/index.ts Line 71 in 9fc79df
|
My sincere apologies. I will spare you the reasons but we are only just now looking to make the switch from MQTT 4.x to 5.x I tested this issue today and unfortunately it remains in the 5.x stream. DetailsI have looked at the src for V5 and it still uses the depreciated
I believe the correct solution is to use the non depreciated way of URL parsing AKA "WHATWG URL API" To provide some weight to this, the Let me look at what is involved in a PR (hopefully not too many places where |
Hi, I am getting an exception when connecting to IPv6 localhost address
::1
I have found this was reported and fixed in #1130 / #1147 (commit 70a247c) however it seems to have been reverted and the current V4.3.7 is once more using the depreciated
url.parse
as you can see here: https://github.com/mqttjs/MQTT.js/blob/main/lib/connect/index.js#L64Here is a minimal repro...
Here is why I think the underlying issue exists:
mqtt.js
manually rebuilds the broker URL using hostname + port inhttps://github.com/mqttjs/MQTT.js/blob/main/lib/connect/ws.js#L20
... but,
url.parse().hostname
drops the squarebrackets off[::1]
which causes the above code to generate the urlhttp://::1:8883
. Further downstream, thews
package usesnew URL(...)
with this re-assembled URL string & theERR_INVALID_URL
error occurs.For anyone else reading, here is a minimal (hacky) workaround...
Additional info...
mqtt.connect(new URL('http://[::1]:8883'))
fails becauseconnect
only accepts astring
orurl.parse
objectmqtt.connect(url.parse('http://[::1]:8883')
fails because unlikenew URL
,url.parse
drops the square brackets offhostname
andmqtt.js uses
hostnameto reassemble the
url`new URL
so whenmqtt.js
passes the reassembled IPhttp://::1:8883
it failes with error ERR_INVALID_URLurl.parse
vsnew URL
url.parse('http://[::1]:8883')
new URL('http://[::1]:8883')
The text was updated successfully, but these errors were encountered: