-
Notifications
You must be signed in to change notification settings - Fork 84
Fix NatsUri not reflecting host/port changes from OnConnectingAsync hook #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix NatsUri not reflecting host/port changes from OnConnectingAsync hook #997
Conversation
|
Thanks @tormoder good catch! this is fixing some of the logging but exceptions are still coming through with the original URI since the fix is done inside |
mtmk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @tormoder, I saw a couple of places exceptions were still reporting the original uri
|
|
||
| if (_socketConnection == null) | ||
| { | ||
| var exception = new NatsException("can not connect uris: " + string.Join(",", uris.Select(x => x.ToString()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is still reporting the original uris
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(NatsLogEvents.Connection, ex, "Fail to connect NATS {Url}", uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still reporting the original
| } | ||
|
|
||
| var connectionFactory = Opts.SocketConnectionFactory ?? (uri.IsWebSocket ? WebSocketFactory.Default : TcpFactory.Default); | ||
| _logger.LogInformation(NatsLogEvents.Connection, "Connect to NATS using {FactoryType} {Uri}", connectionFactory.GetType().Name, uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine
| } | ||
| } | ||
|
|
||
| private async Task ConnectSocketAsync(NatsUri uri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this could return the uri (actually that won't work with exception!)
| var target = (uri.Host, uri.Port); | ||
| if (OnConnectingAsync != null) | ||
| { | ||
| _logger.LogInformation(NatsLogEvents.Connection, "Invoke OnConnectingAsync before connecting to NATS {Uri}", uri); | ||
| target = await OnConnectingAsync(target).ConfigureAwait(false); | ||
| if (target.Host != uri.Host || target.Port != uri.Port) | ||
| { | ||
| uri = uri with { Uri = new UriBuilder(uri.Uri) { Host = target.Host, Port = target.Port, }.Uri }; | ||
| var modifiedUri = new UriBuilder(uri.Uri) { Host = target.Host, Port = target.Port }.Uri; | ||
| uri = new NatsUri(modifiedUri.ToString(), uri.IsSeed, uri.Uri.Scheme); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can be extracted into a method?
|
Thanks, I will take another look. |
|
A bit fiddly, but did another attempt. |
thanks @tormoder yes it looks a bit fiddly :) it seems to work though. I will have a closer look once the other PR is merged that fixes the tests as well. |
Fixes #996.