Connect (seems) to default to port 4222 even when specifying port 80
See original GitHub issueHello! I have a cluster node trying to connect to a load balancer which balances traffic to a nats server. This load balancer is hardcoded to listen to port 80 traffic only, and sadly this behaviour cannot be changed. When using nats.js version 2.5.0, I can’t seem to be able to connect to the load balancer using port 80, as nats.js defaults back to port 4222 as can be seen in the screenshot below:
It looks like the load balancer only allows traffic directly to the port 80, as otherwise the system returns host unreachable and no other kind of connectivity is allowed (even ICMP ping returns host unreachable).
Using the port argument returns connection refused instead.
However, if using netcat (nc
) to put data directly into port 80 of the load balancer, I can see traffic being generated on the nats server as expected.
Client (note that I wrote the {}
manually to trigger an error in the server):
Server:
Any ideas why this could be happening? Thanks in advance!
WORKAROUND
As I needed a way to connect to port 80 of the load balancer, I’ve used the utility socat
to create a local proxy that will redirect outgoing traffic of port 4222 to port 80. This way, I can make nats.js connect to “localhost:4222” and work properly:
socat TCP-LISTEN:4222,fork TCP:<load-balancer-ip-addr>:80 &
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (7 by maintainers)
Top GitHub Comments
@pabmoflo actually you did find an issue. In your exact case the port is “forgotten” - because the code is using
new URL()
to perform some of the parsing:https://github.com/nats-io/nats.deno/blob/main/nats-base-client/servers.ts#L28
URL#port() is returning nothing (it is swallowing, even though it is supposed to report default ports as shown on MDN -https://developer.mozilla.org/en-US/docs/Web/API/URL/port. This basically short-circuits into 4222 - this case is specific I would imagine to 80 and 443. I’ll have a fix for you by tomorrow.
Also you should be able to verify your installed bundles with
npm ls