Skip to content

Fix NATS connection for IP-addressed and path-based event receivers - #71

Merged
ArnobKumarSaha merged 1 commit into
masterfrom
arnob-nats-tls
Aug 12, 2026
Merged

Fix NATS connection for IP-addressed and path-based event receivers#71
ArnobKumarSaha merged 1 commit into
masterfrom
arnob-nats-tls

Conversation

@ArnobKumarSaha

Copy link
Copy Markdown
Member

The websocket handshake in nats.go builds its request URL from the host plus Options.ProxyPath and drops the path of the server URL (ws.go#L617-L625). So a receiver address like wss://10.2.1.39:443/nats requested / instead and failed with:

invalid websocket connection

NewConnection now normalizes the receiver address before connecting:

  • the URL path is stripped from the server list and passed as nats.ProxyPath, so the upgrade request hits /nats
  • a missing port defaults to 443
  • when the receiver is addressed by a bare IP, TLS hostname verification is skipped — an IP can never match the serving cert SANs. Only TLSConfig is set, not nats.Secure(), so a non-TLS server still connects in plain mode.

Also stops the retry ticker on return; it leaked on every NewConnection call.

The websocket handshake builds its request from the host plus
Options.ProxyPath and drops the path of the server URL, so a receiver
address like wss://10.2.1.39:443/nats requested / and failed with
"invalid websocket connection". Pass the path as nats.ProxyPath.

Also default a missing port to 443, and skip TLS hostname verification
when the receiver is addressed by a bare IP, which can never match the
serving cert SANs.

Signed-off-by: Arnob kumar saha <arnob@appscode.com>
@ArnobKumarSaha
ArnobKumarSaha merged commit f81f400 into master Aug 12, 2026
4 checks passed
@ArnobKumarSaha
ArnobKumarSaha deleted the arnob-nats-tls branch August 12, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant