Skip to content

Commit

Permalink
Protected RWLock with try..finally
Browse files Browse the repository at this point in the history
Removes call-stack trashing `throw ex` in the process.
  • Loading branch information
sixlettervariables committed Sep 7, 2016
1 parent 5a6c710 commit 32899cc
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions STAN.CLIENT/AsyncSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ internal static long convertTimeSpan(TimeSpan ts)
// in STAN, much of this code is in the connection module.
internal void subscribe(string subRequestSubject, string subject, string qgroup, EventHandler<StanMsgHandlerArgs> handler)
{
Exception exToThrow = null;

rwLock.EnterWriteLock();

this.handler += handler;
this.subject = subject;

try
{
this.handler += handler;
this.subject = subject;

if (sc == null)
{
throw new StanConnectionClosedException();
Expand Down Expand Up @@ -100,19 +97,19 @@ internal void subscribe(string subRequestSubject, string subject, string qgroup,

ackInbox = r.AckInbox;
}
catch (Exception ex)
catch
{
if (inboxSub != null)
{
inboxSub.Unsubscribe();
}
exToThrow = ex;

throw;
}
finally
{
rwLock.ExitWriteLock();
}

rwLock.ExitWriteLock();

if (exToThrow != null)
throw exToThrow;
}

public void Unsubscribe()
Expand Down

0 comments on commit 32899cc

Please sign in to comment.