@@ -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