@@ -153,7 +153,7 @@ func NewServer(addr address.Address, opts ...ServerOption) (*Server, error) {
153
153
}
154
154
s .desc .Store (description.Server {Addr : addr })
155
155
156
- callback := func (desc description.Server ) { s .updateDescription (desc , false ) }
156
+ callback := func (desc description.Server ) { s .updateDescription (desc ) }
157
157
pc := poolConfig {
158
158
Address : addr ,
159
159
MinPoolSize : cfg .minConns ,
@@ -259,7 +259,8 @@ func (s *Server) Connection(ctx context.Context) (driver.Connection, error) {
259
259
Kind : description .Unknown ,
260
260
LastError : wrappedConnErr ,
261
261
}
262
- s .updateDescription (desc , false )
262
+ s .updateDescription (desc )
263
+ s .pool .clear ()
263
264
264
265
return nil , err
265
266
}
@@ -329,7 +330,7 @@ func (s *Server) ProcessError(err error) {
329
330
desc .Kind = description .Unknown
330
331
desc .LastError = err
331
332
// updates description to unknown
332
- s .updateDescription (desc , false )
333
+ s .updateDescription (desc )
333
334
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
334
335
if cerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
335
336
s .RequestImmediateCheck ()
@@ -342,7 +343,7 @@ func (s *Server) ProcessError(err error) {
342
343
desc .Kind = description .Unknown
343
344
desc .LastError = err
344
345
// updates description to unknown
345
- s .updateDescription (desc , false )
346
+ s .updateDescription (desc )
346
347
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
347
348
if wcerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
348
349
s .RequestImmediateCheck ()
@@ -368,7 +369,7 @@ func (s *Server) ProcessError(err error) {
368
369
desc .Kind = description .Unknown
369
370
desc .LastError = err
370
371
// updates description to unknown
371
- s .updateDescription (desc , false )
372
+ s .updateDescription (desc )
372
373
s .pool .clear ()
373
374
}
374
375
@@ -398,7 +399,7 @@ func (s *Server) update() {
398
399
var desc description.Server
399
400
400
401
desc , conn = s .heartbeat (nil )
401
- s .updateDescription (desc , true )
402
+ s .updateDescription (desc )
402
403
403
404
closeServer := func () {
404
405
doneOnce = true
@@ -438,15 +439,15 @@ func (s *Server) update() {
438
439
}
439
440
440
441
desc , conn = s .heartbeat (conn )
441
- s .updateDescription (desc , false )
442
+ s .updateDescription (desc )
442
443
}
443
444
}
444
445
445
446
// updateDescription handles updating the description on the Server, notifying
446
447
// subscribers, and potentially draining the connection pool. The initial
447
448
// parameter is used to determine if this is the first description from the
448
449
// server.
449
- func (s * Server ) updateDescription (desc description.Server , initial bool ) {
450
+ func (s * Server ) updateDescription (desc description.Server ) {
450
451
defer func () {
451
452
// ¯\_(ツ)_/¯
452
453
_ = recover ()
@@ -469,16 +470,6 @@ func (s *Server) updateDescription(desc description.Server, initial bool) {
469
470
c <- desc
470
471
}
471
472
s .subLock .Unlock ()
472
-
473
- if initial {
474
- // We don't clear the pool on the first update on the description.
475
- return
476
- }
477
-
478
- switch desc .Kind {
479
- case description .Unknown :
480
- s .pool .drain ()
481
- }
482
473
}
483
474
484
475
// heartbeat sends a heartbeat to the server using the given connection. The connection can be nil.
@@ -561,7 +552,7 @@ func (s *Server) heartbeat(conn *connection) (description.Server, *connection) {
561
552
saved = err
562
553
conn = nil
563
554
if wrappedConnErr := unwrapConnectionError (err ); wrappedConnErr != nil {
564
- s .pool .drain ()
555
+ s .pool .clear ()
565
556
// If the server is not connected, give up and exit loop
566
557
if s .Description ().Kind == description .Unknown {
567
558
break
0 commit comments