@@ -135,7 +135,7 @@ func NewServer(addr address.Address, opts ...ServerOption) (*Server, error) {
135
135
136
136
subscribers : make (map [uint64 ]chan description.Server ),
137
137
}
138
- s .desc .Store (description.Server { Addr : addr } )
138
+ s .desc .Store (description .NewDefaultServer ( addr ) )
139
139
140
140
callback := func (desc description.Server ) { s .updateDescription (desc ) }
141
141
pc := poolConfig {
@@ -159,7 +159,7 @@ func (s *Server) Connect(updateCallback func(description.Server)) error {
159
159
if ! atomic .CompareAndSwapInt32 (& s .connectionstate , disconnected , connected ) {
160
160
return ErrServerConnected
161
161
}
162
- s .desc .Store (description.Server { Addr : s .address } )
162
+ s .desc .Store (description .NewDefaultServer ( s .address ) )
163
163
s .updateTopologyCallback .Store (updateCallback )
164
164
go s .update ()
165
165
s .closewg .Add (1 )
@@ -226,10 +226,7 @@ func (s *Server) Connection(ctx context.Context) (driver.Connection, error) {
226
226
227
227
// Since the only kind of ConnectionError we receive from pool.Get will be an initialization
228
228
// error, we should set the description.Server appropriately.
229
- desc := description.Server {
230
- Kind : description .Unknown ,
231
- LastError : wrappedConnErr ,
232
- }
229
+ desc := description .NewServerFromError (s .address , wrappedConnErr )
233
230
s .updateDescription (desc )
234
231
s .pool .clear ()
235
232
@@ -294,14 +291,12 @@ func (s *Server) RequestImmediateCheck() {
294
291
295
292
// ProcessError handles SDAM error handling and implements driver.ErrorProcessor.
296
293
func (s * Server ) ProcessError (err error ) {
294
+ desc := s .Description ()
297
295
// Invalidate server description if not master or node recovering error occurs.
298
296
// These errors can be reported as a command error or a write concern error.
299
297
if cerr , ok := err .(driver.Error ); ok && (cerr .NodeIsRecovering () || cerr .NotMaster ()) {
300
- desc := s .Description ()
301
- desc .Kind = description .Unknown
302
- desc .LastError = err
303
298
// updates description to unknown
304
- s .updateDescription (desc )
299
+ s .updateDescription (description . NewServerFromError ( s . address , err ) )
305
300
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
306
301
if cerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
307
302
s .RequestImmediateCheck ()
@@ -310,11 +305,8 @@ func (s *Server) ProcessError(err error) {
310
305
return
311
306
}
312
307
if wcerr , ok := err .(driver.WriteConcernError ); ok && (wcerr .NodeIsRecovering () || wcerr .NotMaster ()) {
313
- desc := s .Description ()
314
- desc .Kind = description .Unknown
315
- desc .LastError = err
316
308
// updates description to unknown
317
- s .updateDescription (desc )
309
+ s .updateDescription (description . NewServerFromError ( s . address , err ) )
318
310
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
319
311
if wcerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
320
312
s .RequestImmediateCheck ()
@@ -336,11 +328,8 @@ func (s *Server) ProcessError(err error) {
336
328
return
337
329
}
338
330
339
- desc := s .Description ()
340
- desc .Kind = description .Unknown
341
- desc .LastError = err
342
331
// updates description to unknown
343
- s .updateDescription (desc )
332
+ s .updateDescription (description . NewServerFromError ( s . address , err ) )
344
333
s .pool .clear ()
345
334
}
346
335
@@ -541,11 +530,7 @@ func (s *Server) heartbeat(conn *connection) (description.Server, *connection) {
541
530
}
542
531
543
532
if ! set {
544
- desc = description.Server {
545
- Addr : s .address ,
546
- LastError : saved ,
547
- Kind : description .Unknown ,
548
- }
533
+ desc = description .NewServerFromError (s .address , saved )
549
534
}
550
535
551
536
return desc , conn
0 commit comments