@@ -219,15 +219,15 @@ public IPEndPoint GetIPEndPoint()
219219 /// </summary>
220220 public void Ping ( )
221221 {
222- var connection = _connectionPool . AcquireConnection ( null ) ;
222+ // use a new connection instead of one from the connection pool
223+ var connection = new MongoConnection ( this ) ;
223224 try
224225 {
225- var pingCommand = new CommandDocument ( "ping" , 1 ) ;
226- connection . RunCommand ( "admin.$cmd" , QueryFlags . SlaveOk , pingCommand , true ) ;
226+ Ping ( connection ) ;
227227 }
228228 finally
229229 {
230- _connectionPool . ReleaseConnection ( connection ) ;
230+ connection . Close ( ) ;
231231 }
232232 }
233233
@@ -238,21 +238,22 @@ public void VerifyState()
238238 {
239239 lock ( _serverInstanceLock )
240240 {
241- // Console.WriteLine("MongoServerInstance[{0}]: VerifyState called.", sequentialId);
242- // if ping fails assume all connections in the connection pool are doomed
241+ // use a new connection instead of one from the connection pool
242+ var connection = new MongoConnection ( this ) ;
243243 try
244244 {
245- Ping ( ) ;
246- }
247- catch
248- {
249- // Console.WriteLine("MongoServerInstance[{0}]: Ping failed: {1}.", sequentialId, ex.Message);
250- _connectionPool . Clear ( ) ;
251- }
245+ // Console.WriteLine("MongoServerInstance[{0}]: VerifyState called.", sequentialId);
246+ // if ping fails assume all connections in the connection pool are doomed
247+ try
248+ {
249+ Ping ( connection ) ;
250+ }
251+ catch
252+ {
253+ // Console.WriteLine("MongoServerInstance[{0}]: Ping failed: {1}.", sequentialId, ex.Message);
254+ _connectionPool . Clear ( ) ;
255+ }
252256
253- var connection = _connectionPool . AcquireConnection ( null ) ;
254- try
255- {
256257 var previousState = _state ;
257258 try
258259 {
@@ -270,7 +271,7 @@ public void VerifyState()
270271 }
271272 finally
272273 {
273- _connectionPool . ReleaseConnection ( connection ) ;
274+ connection . Close ( ) ;
274275 }
275276 }
276277 }
@@ -373,6 +374,12 @@ internal void Disconnect()
373374 }
374375 }
375376
377+ internal void Ping ( MongoConnection connection )
378+ {
379+ var pingCommand = new CommandDocument ( "ping" , 1 ) ;
380+ connection . RunCommand ( "admin.$cmd" , QueryFlags . SlaveOk , pingCommand , true ) ;
381+ }
382+
376383 internal void ReleaseConnection ( MongoConnection connection )
377384 {
378385 _connectionPool . ReleaseConnection ( connection ) ;
0 commit comments