Skip to content

Commit 5a3d63f

Browse files
author
Elad Zelingher
committed
Trying to fix #167
1 parent 2f94e13 commit 5a3d63f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/net45/WampSharp/WAMP2/V2/Client/Session/WampSessionClient.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public void Goodbye(GoodbyeDetails details, string reason)
113113

114114
private void RaiseConnectionBroken(SessionCloseType sessionCloseType, GoodbyeAbortDetails details, string reason)
115115
{
116+
bool connectionBrokenRaised = mConnectionBrokenRaised;
117+
116118
mConnectionBrokenRaised = true;
117119

118120
WampSessionCloseEventArgs closeEventArgs = new WampSessionCloseEventArgs
@@ -122,13 +124,19 @@ private void RaiseConnectionBroken(SessionCloseType sessionCloseType, GoodbyeAbo
122124

123125
SetOpenTaskErrorIfNeeded(new WampConnectionBrokenException(closeEventArgs));
124126

125-
Interlocked.CompareExchange(ref mIsConnected, 0, 1);
127+
if (sessionCloseType == SessionCloseType.Disconnection)
128+
{
129+
Interlocked.CompareExchange(ref mIsConnected, 0, 1);
126130

127-
mOpenTask = new TaskCompletionSource<bool>();
131+
mOpenTask = new TaskCompletionSource<bool>();
128132

129-
mConnectionBrokenRaised = false;
133+
mConnectionBrokenRaised = false;
134+
}
130135

131-
OnConnectionBroken(closeEventArgs);
136+
if (!connectionBrokenRaised)
137+
{
138+
OnConnectionBroken(closeEventArgs);
139+
}
132140
}
133141

134142
public long Session
@@ -189,12 +197,9 @@ public void OnConnectionClosed()
189197
{
190198
SetOpenTaskErrorIfNeeded(new Exception("Connection closed before connection established."));
191199

192-
if (!mConnectionBrokenRaised)
193-
{
194-
RaiseConnectionBroken(SessionCloseType.Disconnection,
195-
null,
196-
null);
197-
}
200+
RaiseConnectionBroken(SessionCloseType.Disconnection,
201+
null,
202+
null);
198203
}
199204

200205
public void OnConnectionError(Exception exception)

0 commit comments

Comments
 (0)