Skip to content

Commit 81a613d

Browse files
committed
bugfix: queue/Example_connectionPool data race
Part of #218
1 parent bda241e commit 81a613d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

queue/example_connection_pool_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func (h *QueueConnectionHandler) Discovered(conn *tarantool.Connection,
8989
}
9090
}
9191

92-
atomic.AddInt32(&h.masterCnt, 1)
9392
fmt.Printf("Master %s is ready to work!\n", conn.Addr())
93+
atomic.AddInt32(&h.masterCnt, 1)
9494

9595
return nil
9696
}
@@ -185,8 +185,12 @@ func Example_connectionPool() {
185185

186186
// Wait for a new master instance re-identification.
187187
<-h.masterUpdated
188-
if h.err != nil {
189-
fmt.Printf("Unable to re-identify in the pool: %s", h.err)
188+
h.mutex.Lock()
189+
err = h.err
190+
h.mutex.Unlock()
191+
192+
if err != nil {
193+
fmt.Printf("Unable to re-identify in the pool: %s", err)
190194
return
191195
}
192196

0 commit comments

Comments
 (0)