-
Notifications
You must be signed in to change notification settings - Fork 85
Open
Labels
Description
Observed behavior
When using the OnConncetAsync hook, exceptions and logs show the original URI (from NatsOpts) because ToString() returns the cached NatsUri _redacted value from before the modification.
This is especially confusing if connecting fails, because logs and error messages e.g. says the default localhost:4222 was used, and leads you to thinking that the address from the hook was not applied/used.
| uri = uri with { Uri = new UriBuilder(uri.Uri) { Host = target.Host, Port = target.Port, }.Uri }; |
- The
withexpression creates a newNatsUrirecord with only theUriproperty changed. _redactedfield in NatsUri is only set in the constructor.- Using
with, the _redacted field is shallow copied from the original instance. ToString()returns the original URI string, not the modified one.
Expected behavior
When OnConnectingAsync changes the host/port, exceptions and logs should show the modified URI that was actually used for connection.
Server and client version
NATS Server: 2.11
NATS.NET: 2.6.6
Host environment
N/A
Steps to reproduce
- Set the
OnConnectingAsynchook to return a host+port for which a connection will fail (but different fromlocalhost:4222or yourNatsOptsvalue). - Observe URI used for log statements in
ConnectSocketAsync. - Look at URI used in exception thrown when connection fails.
mtmk