Repository navigation
Conversation
… of the server that reported them, skipped entries reported - A connect_urls entry is taken as host:port, the form nats-server writes, with an IPv6 address in brackets. User info in an entry is dropped; the discovered server is sent the credentials used for the server that reported it. An entry that carries a scheme is skipped as a whole, not reduced to its host and port. An entry that does not parse as host:port, or whose port is outside 1 to 65535, is skipped. The other entries of the INFO are used. The rule is NatsUri.discoveredHostPort; NatsConnection.handleInfo applies it before the pool sees the list, so a custom ServerPool receives host:port entries only, and NatsServerPool applies it as well. - A discovered server takes the scheme of the server that reported it, so it is dialed with that server's transport and TLS: an entry learned over wss:// becomes a wss:// server. Without an origin the pool's default scheme applies as before. A configured server named by an entry does not change. - Each skipped entry is reported through the new ErrorListener.discoveredServerSkipped(Connection, String entry, String reason), once per entry each time an INFO carries it. The logger and console listeners log it at WARNING with the entry quoted by quoteUntrusted, control characters escaped. - The runtime rejection of a ws:// server when the options require TLS stays, for a custom ServerPool; a connect_urls entry can no longer bring one. - README paragraph under the SSLContext rules; docs/TLS_CONFIGURATION.md section 1 and new section 10. - Tests: OptionsTests.testNatsUriDiscoveredHostPort, 20 used and 54 skipped forms including the parser-confusing ones; ServerPoolTests for the origin's scheme, the hygiene rule and dropped user info, entries as host:port throughout; TLSConnectTests entries with a scheme are skipped, reported and never dialed; ReconnectTests user info in an entry is not sent as credentials; ConnectionListenerTests a scheme-bearing entry discovers nothing; ListenerForTesting records the reports.
|
Claude finished @scottf's task in 3m 16s —— View job Review complete
I reviewed the implementation of Correctness
Security
Nits (not blocking)
Overall the change is well-scoped, the parsing logic matches the documented ADR-40 rules, and test coverage is thorough (unit-level |
|
On the |
Follows #1641 and #1666, both merged. How the client takes the entries of
connect_urls, and how it dials the servers it learns from them.An entry is
host:port. That is the form nats-server writes, with an IPv6 address in brackets, and it is now the only form the client uses. User info in an entry,user:pass@host:port, is dropped: the discovered server is sent the credentials the client uses for the server that reported it, as before. An entry that carries a scheme,nats://host:portorws://host:port, is skipped as a whole, not reduced to its host and port. An entry that does not parse ashost:portonce its user info is dropped, or whose port is outside 1 to 65535, is skipped. The other entries of the INFO are still used. The rule isNatsUri.discoveredHostPort, applied inNatsConnection.handleInfobefore the pool sees the list and again inNatsServerPool. nats-server never writes user info or a scheme into an entry, so nothing a cluster advertises changes; a proxy that rewrites entries into URLs loses them, and is told so.A discovered server is dialed the way the server that reported it was dialed. It takes that server's scheme, so it gets the same transport and, the context being per connection, the same TLS: an entry learned over
wss://becomes awss://server, one learned overtls://atls://server. Until now a discovered server took the scheme of the first configured server that was not plainnats://, which in a list that mixes WebSocket and TCP servers could be the wrong transport. Without an origin the default scheme applies as before. A configured server named by an entry does not change.Skipped entries are reported. New
ErrorListener.discoveredServerSkipped(Connection conn, String entry, String reason), a default method, called once per skipped entry each time an INFO carries it, with the entry as the server sent it. The logger and console listeners log it at WARNING with the entry quoted and control characters escaped. The runtime rejection from #1641 stays for aws://server a customServerPoolhands out; aconnect_urlsentry can no longer bring one.For custom
ServerPoolimplementations:acceptDiscoveredUrlsnow receiveshost:portstrings only, never an entry with a scheme or with user info. A pool that gave its discovered servers a scheme from the entry has to take it from theoriginofacceptDiscoveredUrls(List, NatsUri)instead, asNatsServerPooldoes.Docs: README paragraph under the SSLContext rules;
docs/TLS_CONFIGURATION.mdsection 1 and new section 10.Tests:
OptionsTests.testNatsUriDiscoveredHostPortruns 20 used and 54 skipped forms, including entries written to confuse a URL parser (embedded control characters, mixed-case and percent-encoded schemes, path, query and fragment characters, bracket and numeric forms).ServerPoolTests: a discovered server takes the origin's scheme over one and two hops, the first report decides, configured servers do not change; the hygiene rule at the pool; user info in an entry is dropped and the origin's inherited.TLSConnectTests: entries withws://,nats://,tls://andwss://schemes are skipped, reported once each per INFO, never pooled and never dialed, while thehost:portentry next to them is pooled astls://.ReconnectTests: an entry with user info does not log in as that user; the reconnect uses the configured url's credentials.ConnectionListenerTests: a scheme-bearing entry discovers nothing and is reported. Seven of these fail without the behavior change; the five untouchedServerPoolTestspass either way.