@@ -66,7 +66,7 @@ protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFact
6666 _description = ClusterDescription . CreateInitial ( _clusterId , _settings . ConnectionMode . ToClusterType ( ) ) ;
6767 _descriptionChangedTaskCompletionSource = new TaskCompletionSource < bool > ( ) ;
6868
69- _rapidHeartbeatTimer = new Timer ( o => RequestHeartbeat ( ) , null , Timeout . InfiniteTimeSpan , Timeout . InfiniteTimeSpan ) ;
69+ _rapidHeartbeatTimer = new Timer ( RapidHeartbeatTimerCallback , null , Timeout . InfiniteTimeSpan , Timeout . InfiniteTimeSpan ) ;
7070 }
7171
7272 // events
@@ -159,6 +159,20 @@ public virtual void Initialize()
159159 _state . TryChange ( State . Initial , State . Open ) ;
160160 }
161161
162+ private void RapidHeartbeatTimerCallback ( object args )
163+ {
164+ try
165+ {
166+ RequestHeartbeat ( ) ;
167+ }
168+ catch
169+ {
170+ // TODO: Trace this
171+ // If we don't protect this call, we could
172+ // take down the app domain.
173+ }
174+ }
175+
162176 protected abstract void RequestHeartbeat ( ) ;
163177
164178 protected void OnDescriptionChanged ( ClusterDescription oldDescription , ClusterDescription newDescription )
@@ -188,14 +202,14 @@ public async Task<IServer> SelectServerAsync(IServerSelector selector, Cancellat
188202 if ( _settings . PreServerSelector != null || _settings . PostServerSelector != null )
189203 {
190204 var allSelectors = new List < IServerSelector > ( ) ;
191- if ( _settings . PreServerSelector != null )
205+ if ( _settings . PreServerSelector != null )
192206 {
193207 allSelectors . Add ( _settings . PreServerSelector ) ;
194208 }
195209
196210 allSelectors . Add ( selector ) ;
197211
198- if ( _settings . PostServerSelector != null )
212+ if ( _settings . PostServerSelector != null )
199213 {
200214 allSelectors . Add ( _settings . PostServerSelector ) ;
201215 }
0 commit comments