question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connect (seems) to default to port 4222 even when specifying port 80

See original GitHub issue

Hello! 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:

image

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. WindowsTerminal_1LrSbHi4Zl

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): WindowsTerminal_WHdzQYYsO5

Server: image

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:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
aricartcommented, Jan 30, 2022

@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.

0reactions
aricartcommented, Jan 30, 2022

Also you should be able to verify your installed bundles with npm ls

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting "Port 80 in use issue" - Anash's Knowledge ...
As port 80 is the default port for http, the most likely reason is that another web server (like IIS) is running on...
Read more >
Why do we need to specify a port number while using HTTP ...
The default port for HTTP is 80 and HTTPS is 443 but port numbers range from 0 to 65535. Most web servers listen...
Read more >
Why was port 80 chosen as the default HTTP port and 443 as ...
If the port number is not specified, 80 is always assumed for HTTP. Then in July 1992 was published RFC 1340 that obsoletes...
Read more >
Change the Port Number for HTTP Redirection to Connection ...
Verify that you changed the default port number from 443. If you use the default values that are configured during installation, you do...
Read more >
Why only port 80 for web services?
Port 80 is a well-known port, which means it is well-known as the location you'll normally find HTTP servers. You can find it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found