Skip to content

Commit 8709a93

Browse files
committed
bugfix: read state data race
We need to use an atomic method to read the atomic value. Part of #218
1 parent 35939df commit 8709a93

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

connection.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ func (conn *Connection) newFuture(ctx context.Context) (fut *Future) {
10331033
shardn := fut.requestId & (conn.opts.Concurrency - 1)
10341034
shard := &conn.shard[shardn]
10351035
shard.rmut.Lock()
1036-
switch conn.state {
1036+
switch atomic.LoadUint32(&conn.state) {
10371037
case connClosed:
10381038
fut.err = ClientError{
10391039
ErrConnectionClosed,
@@ -1730,9 +1730,10 @@ func (conn *Connection) shutdown() {
17301730
conn.mutex.Lock()
17311731
defer conn.mutex.Unlock()
17321732

1733-
if !atomic.CompareAndSwapUint32(&(conn.state), connConnected, connShutdown) {
1733+
if !atomic.CompareAndSwapUint32(&conn.state, connConnected, connShutdown) {
17341734
return
17351735
}
1736+
17361737
conn.cond.Broadcast()
17371738
conn.notify(Shutdown)
17381739

0 commit comments

Comments
 (0)