Skip to content

Commit

Permalink
Do not disconnect on NATSReconnectBufferException (#165)
Browse files Browse the repository at this point in the history
* Do not disconnect on NATSReconnectBufferException and handle all ping exceptions

Signed-off-by: Colin Sullivan <[email protected]>
  • Loading branch information
ColinSullivan1 authored Dec 24, 2019
1 parent e70af66 commit be92e79
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/STAN.Client/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public IConnection NatsConn
{
set
{
if(value != null && value.Opts.ReconnectBufferSize != Options.ReconnectBufferDisabled)
throw new ArgumentException("The underlying NATS connection should have buffers during reconnect disabled. E.g controlled via: 'Opts.ReconnectBufferSize = Options.ReconnectBufferDisabled'", nameof(value));

// TODO: Override NATS connection buffer settings.
natsConn = value;
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/STAN.Client/StanConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ internal Connection(string stanClusterID, string clientID, StanOptions options)
private void pingServer(object state)
{
IConnection conn = null;
Exception pingEx = null;
bool lostConnection = false;

lock (pingLock)
Expand All @@ -358,7 +357,6 @@ private void pingServer(object state)
if (pingOut > pingMaxOut)
{
lostConnection = true;
pingEx = new StanMaxPingsException();
}
else
{
Expand All @@ -369,7 +367,7 @@ private void pingServer(object state)

if (lostConnection)
{
closeDueToPing(pingEx);
closeDueToPing(new StanMaxPingsException());
return;
}

Expand All @@ -380,11 +378,11 @@ private void pingServer(object state)
catch (Exception ex)
when (
ex is NATSConnectionClosedException ||
ex is NATSStaleConnectionException ||
ex is NATSReconnectBufferException)
ex is NATSStaleConnectionException)
{
closeDueToPing(ex);
}
catch { /* ignore other publish exceptions */ }
}

private void closeDueToPing(Exception ex)
Expand Down

0 comments on commit be92e79

Please sign in to comment.