File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -591,6 +591,8 @@ func (t *Topology) addServer(addr address.Address) error {
591
591
func (t * Topology ) String () string {
592
592
desc := t .Description ()
593
593
str := fmt .Sprintf ("Type: %s\n Servers:\n " , desc .Kind )
594
+ t .serversLock .Lock ()
595
+ defer t .serversLock .Unlock ()
594
596
for _ , s := range t .servers {
595
597
str += s .String () + "\n "
596
598
}
Original file line number Diff line number Diff line change @@ -455,3 +455,27 @@ func TestMinPoolSize(t *testing.T) {
455
455
t .Errorf ("topology.Connect shouldn't error. got: %v" , err )
456
456
}
457
457
}
458
+
459
+ func TestTopology_String_Race (t * testing.T ) {
460
+ ch := make (chan bool )
461
+ topo := & Topology {
462
+ servers : make (map [address.Address ]* Server ),
463
+ }
464
+
465
+ go func () {
466
+ topo .serversLock .Lock ()
467
+ srv := & Server {}
468
+ srv .desc .Store (description.Server {})
469
+ topo .servers [address .Address ("127.0.0.1:27017" )] = srv
470
+ topo .serversLock .Unlock ()
471
+ ch <- true
472
+ }()
473
+
474
+ go func () {
475
+ topo .String ()
476
+ ch <- true
477
+ }()
478
+
479
+ <- ch
480
+ <- ch
481
+ }
You can’t perform that action at this time.
0 commit comments