Skip to content

Fix leaf node advertisement with no_advertise - #8451

Open
freakes wants to merge 1 commit into
nats-io:mainfrom
freakes:fix/leafnode-no-advertise
Open

Fix leaf node advertisement with no_advertise#8451
freakes wants to merge 1 commit into
nats-io:mainfrom
freakes:fix/leafnode-no-advertise

Conversation

@freakes

@freakes freakes commented Aug 11, 2026

Copy link
Copy Markdown

Summary

Respect leafnodes.no_advertise when advertising leaf-node listener URLs.

Previously, the server always added its own leaf listener address to the
advertised leaf-node URL set. As a result, connected leaf nodes could learn
the hub address and later try to reconnect to it even when no_advertise
was enabled.

Avoid adding the local leaf listener URL when no_advertise is set.

This also means a legitimate initial leaf INFO may contain no
LeafNodeURLs. Update the solicited leaf handshake validation so an
InfoOnConnect INFO without advertised leaf URLs is not incorrectly
classified as a wrong-port connection.

Tests

Added regression coverage for:

  • a hub configured with leafnodes.no_advertise=true not leaking its leaf
    listener into the leaf's reconnect URL set
  • accepting a legitimate InfoOnConnect leaf INFO without LeafNodeURLs
  • preserving existing wrong-port detection behavior

Verified with:

go test ./server -run '^TestLeafNodeNoAdvertiseDoesNotAdvertiseListener$' -count=20
go test ./server -run '^TestLeafNodeInfoOnConnectWithoutLeafNodeURLsAccepted$' -count=20
go test ./server -run '^TestLeafNodeRemoteWrongPort$' -count=20
go test ./server -run 'LeafNode.*WrongPort|LeafNodeNoAdvertise' -count=10

Resolves #8367

Signed-off-by: freakes <ISergey2022@gmail.com>
@freakes
freakes requested a review from a team as a code owner August 11, 2026 13:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38e115330f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread server/leafnode.go
Comment on lines +1033 to +1035
if !opts.LeafNode.NoAdvertise {
s.leafURLsMap[s.leafNodeInfo.IP]++
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clear discovered leaf URLs when advertisements become empty

When leafnodes.no_advertise suppresses the server's own URL, leafURLsMap can now legitimately become empty after the last routed server that advertised a leaf URL disconnects. removeLeafNodeURL will send an async INFO with no leafnode_urls, but soliciting leaves only refresh discovered URLs when the incoming INFO has a non-empty URL list, so they keep stale discovered peers instead of falling back to the configured remote. In a no-advertise hub cluster, this leaves leaf nodes reconnecting to removed peers; empty async advertisements need to be applied as the current URL set too.

Useful? React with 👍 / 👎.

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.

Hub IPs are leaking to leafnodes even if no_advertise is set to true

1 participant