@@ -148,7 +148,7 @@ func NewServer(addr address.Address, opts ...ServerOption) (*Server, error) {
148
148
}
149
149
s .desc .Store (description.Server {Addr : addr })
150
150
151
- callback := func (desc description.Server ) { s .updateDescription (desc , false ) }
151
+ callback := func (desc description.Server ) { s .updateDescription (desc ) }
152
152
pc := poolConfig {
153
153
Address : addr ,
154
154
MinPoolSize : cfg .minConns ,
@@ -254,7 +254,8 @@ func (s *Server) Connection(ctx context.Context) (driver.Connection, error) {
254
254
Kind : description .Unknown ,
255
255
LastError : wrappedConnErr ,
256
256
}
257
- s .updateDescription (desc , false )
257
+ s .updateDescription (desc )
258
+ s .pool .clear ()
258
259
259
260
return nil , err
260
261
}
@@ -324,7 +325,7 @@ func (s *Server) ProcessError(err error) {
324
325
desc .Kind = description .Unknown
325
326
desc .LastError = err
326
327
// updates description to unknown
327
- s .updateDescription (desc , false )
328
+ s .updateDescription (desc )
328
329
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
329
330
if cerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
330
331
s .RequestImmediateCheck ()
@@ -337,7 +338,7 @@ func (s *Server) ProcessError(err error) {
337
338
desc .Kind = description .Unknown
338
339
desc .LastError = err
339
340
// updates description to unknown
340
- s .updateDescription (desc , false )
341
+ s .updateDescription (desc )
341
342
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
342
343
if wcerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
343
344
s .RequestImmediateCheck ()
@@ -363,7 +364,7 @@ func (s *Server) ProcessError(err error) {
363
364
desc .Kind = description .Unknown
364
365
desc .LastError = err
365
366
// updates description to unknown
366
- s .updateDescription (desc , false )
367
+ s .updateDescription (desc )
367
368
s .pool .clear ()
368
369
}
369
370
@@ -393,7 +394,7 @@ func (s *Server) update() {
393
394
var desc description.Server
394
395
395
396
desc , conn = s .heartbeat (nil )
396
- s .updateDescription (desc , true )
397
+ s .updateDescription (desc )
397
398
398
399
closeServer := func () {
399
400
doneOnce = true
@@ -433,15 +434,15 @@ func (s *Server) update() {
433
434
}
434
435
435
436
desc , conn = s .heartbeat (conn )
436
- s .updateDescription (desc , false )
437
+ s .updateDescription (desc )
437
438
}
438
439
}
439
440
440
441
// updateDescription handles updating the description on the Server, notifying
441
442
// subscribers, and potentially draining the connection pool. The initial
442
443
// parameter is used to determine if this is the first description from the
443
444
// server.
444
- func (s * Server ) updateDescription (desc description.Server , initial bool ) {
445
+ func (s * Server ) updateDescription (desc description.Server ) {
445
446
defer func () {
446
447
// ¯\_(ツ)_/¯
447
448
_ = recover ()
@@ -463,16 +464,6 @@ func (s *Server) updateDescription(desc description.Server, initial bool) {
463
464
c <- desc
464
465
}
465
466
s .subLock .Unlock ()
466
-
467
- if initial {
468
- // We don't clear the pool on the first update on the description.
469
- return
470
- }
471
-
472
- switch desc .Kind {
473
- case description .Unknown :
474
- s .pool .drain ()
475
- }
476
467
}
477
468
478
469
// heartbeat sends a heartbeat to the server using the given connection. The connection can be nil.
@@ -555,7 +546,7 @@ func (s *Server) heartbeat(conn *connection) (description.Server, *connection) {
555
546
saved = err
556
547
conn = nil
557
548
if wrappedConnErr := unwrapConnectionError (err ); wrappedConnErr != nil {
558
- s .pool .drain ()
549
+ s .pool .clear ()
559
550
// If the server is not connected, give up and exit loop
560
551
if s .Description ().Kind == description .Unknown {
561
552
break
0 commit comments