@@ -126,8 +126,8 @@ public IRedisPubSubServer Start()
126126 }
127127 catch ( Exception ex )
128128 {
129- ex . Message . Print ( ) ;
130- if ( this . OnError != null ) this . OnError ( ex ) ;
129+ if ( this . OnError != null )
130+ this . OnError ( ex ) ;
131131 }
132132 }
133133
@@ -136,10 +136,18 @@ public IRedisPubSubServer Start()
136136
137137 private void Init ( )
138138 {
139- using ( var redis = ClientsManager . GetReadOnlyClient ( ) )
139+ try
140+ {
141+ using ( var redis = ClientsManager . GetReadOnlyClient ( ) )
142+ {
143+ startedAt = Stopwatch . StartNew ( ) ;
144+ serverTimeAtStart = redis . GetServerTime ( ) ;
145+ }
146+ }
147+ catch ( Exception ex )
140148 {
141- serverTimeAtStart = redis . GetServerTime ( ) ;
142- startedAt = Stopwatch . StartNew ( ) ;
149+ if ( OnError != null )
150+ OnError ( ex ) ;
143151 }
144152
145153 DisposeHeartbeatTimer ( ) ;
@@ -161,14 +169,18 @@ void SendHeartbeat(object state)
161169 if ( OnHeartbeatSent != null )
162170 OnHeartbeatSent ( ) ;
163171
164- if ( Interlocked . CompareExchange ( ref status , 0 , 0 ) != Status . Started )
172+ var currentStatus = Interlocked . CompareExchange ( ref status , 0 , 0 ) ;
173+ if ( currentStatus != Status . Started )
174+ {
165175 return ;
176+ }
166177
167178 NotifyAllSubscribers ( ControlCommand . Pulse ) ;
168179
169180 if ( DateTime . UtcNow - new DateTime ( lastHeartbeatTicks ) > HeartbeatTimeout )
170181 {
171- if ( Interlocked . CompareExchange ( ref status , 0 , 0 ) == Status . Started )
182+ currentStatus = Interlocked . CompareExchange ( ref status , 0 , 0 ) ;
183+ if ( currentStatus == Status . Started )
172184 {
173185 Restart ( ) ;
174186 }
0 commit comments