@@ -140,7 +140,7 @@ func NewServer(addr address.Address, opts ...ServerOption) (*Server, error) {
140
140
141
141
subscribers : make (map [uint64 ]chan description.Server ),
142
142
}
143
- s .desc .Store (description.Server { Addr : addr } )
143
+ s .desc .Store (description .NewDefaultServer ( addr ) )
144
144
145
145
callback := func (desc description.Server ) { s .updateDescription (desc ) }
146
146
pc := poolConfig {
@@ -164,7 +164,7 @@ func (s *Server) Connect(updateCallback updateTopologyCallback) error {
164
164
if ! atomic .CompareAndSwapInt32 (& s .connectionstate , disconnected , connected ) {
165
165
return ErrServerConnected
166
166
}
167
- s .desc .Store (description.Server { Addr : s .address } )
167
+ s .desc .Store (description .NewDefaultServer ( s .address ) )
168
168
s .updateTopologyCallback .Store (updateCallback )
169
169
go s .update ()
170
170
s .closewg .Add (1 )
@@ -231,10 +231,7 @@ func (s *Server) Connection(ctx context.Context) (driver.Connection, error) {
231
231
232
232
// Since the only kind of ConnectionError we receive from pool.Get will be an initialization
233
233
// error, we should set the description.Server appropriately.
234
- desc := description.Server {
235
- Kind : description .Unknown ,
236
- LastError : wrappedConnErr ,
237
- }
234
+ desc := description .NewServerFromError (s .address , wrappedConnErr )
238
235
s .updateDescription (desc )
239
236
s .pool .clear ()
240
237
@@ -299,14 +296,12 @@ func (s *Server) RequestImmediateCheck() {
299
296
300
297
// ProcessError handles SDAM error handling and implements driver.ErrorProcessor.
301
298
func (s * Server ) ProcessError (err error ) {
299
+ desc := s .Description ()
302
300
// Invalidate server description if not master or node recovering error occurs.
303
301
// These errors can be reported as a command error or a write concern error.
304
302
if cerr , ok := err .(driver.Error ); ok && (cerr .NodeIsRecovering () || cerr .NotMaster ()) {
305
- desc := s .Description ()
306
- desc .Kind = description .Unknown
307
- desc .LastError = err
308
303
// updates description to unknown
309
- s .updateDescription (desc )
304
+ s .updateDescription (description . NewServerFromError ( s . address , err ) )
310
305
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
311
306
if cerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
312
307
s .RequestImmediateCheck ()
@@ -315,11 +310,8 @@ func (s *Server) ProcessError(err error) {
315
310
return
316
311
}
317
312
if wcerr , ok := err .(driver.WriteConcernError ); ok && (wcerr .NodeIsRecovering () || wcerr .NotMaster ()) {
318
- desc := s .Description ()
319
- desc .Kind = description .Unknown
320
- desc .LastError = err
321
313
// updates description to unknown
322
- s .updateDescription (desc )
314
+ s .updateDescription (description . NewServerFromError ( s . address , err ) )
323
315
// If the node is shutting down or is older than 4.2, we synchronously clear the pool
324
316
if wcerr .NodeIsShuttingDown () || desc .WireVersion == nil || desc .WireVersion .Max < 8 {
325
317
s .RequestImmediateCheck ()
@@ -341,11 +333,8 @@ func (s *Server) ProcessError(err error) {
341
333
return
342
334
}
343
335
344
- desc := s .Description ()
345
- desc .Kind = description .Unknown
346
- desc .LastError = err
347
336
// updates description to unknown
348
- s .updateDescription (desc )
337
+ s .updateDescription (description . NewServerFromError ( s . address , err ) )
349
338
s .pool .clear ()
350
339
}
351
340
@@ -547,11 +536,7 @@ func (s *Server) heartbeat(conn *connection) (description.Server, *connection) {
547
536
}
548
537
549
538
if ! set {
550
- desc = description.Server {
551
- Addr : s .address ,
552
- LastError : saved ,
553
- Kind : description .Unknown ,
554
- }
539
+ desc = description .NewServerFromError (s .address , saved )
555
540
}
556
541
557
542
return desc , conn
0 commit comments