nats-io / nats.net

Full Async C# / .NET client for NATS
https://nats-io.github.io/nats.net
Apache License 2.0
272 stars 55 forks source link

Add (force) reconnect method #479

Open mtmk opened 7 months ago

mtmk commented 7 months ago
mtmk commented 6 months ago

This should be as simple as closing the socket and let the retry logic take its course.

pzajaczkowski commented 1 day ago

Hi Guys! I'd like to contribute and have a few questions.

  1. What should be the desired behavior when invoking ReconnectAsync on a closed connection? Should it attempt to reconnect, or just return without doing anything?

  2. I'm also considering adding some wait logic to ensure that the ReconnectAsync task completes when the reconnection succeeds. I've been thinking about a temporary ConnectionOpened event subscription for this purpose. Would this approach make sense, or is there a preferred pattern for handling this?

mtmk commented 1 day ago

Hi Guys! I'd like to contribute and have a few questions.

thank you @pzajaczkowski 🎉

  1. What should be the desired behavior when invoking ReconnectAsync on a closed connection? Should it attempt to reconnect, or just return without doing anything?

if the connection is not open reconnect loop should be running behind the scenes to bring the connection up so it makes sense to not do anything in that case.

  1. I'm also considering adding some wait logic to ensure that the ReconnectAsync task completes when the reconnection succeeds. I've been thinking about a temporary ConnectionOpened event subscription for this purpose. Would this approach make sense, or is there a preferred pattern for handling this?

what would be the use case for that? The name might not make sense in this case I guess so maybe name as ForceReconnectAsync() instead? the reason I'm asking is that one scenario for this is to initiate a reconnect after receiving a LDM message from the server and the callback for it should just issue a reconnect but won't need to wait for the reconnection to happen. see also #23

feel free to start a PR we can discuss the details there