Skip to content

Commit d7974ea

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 11b716d commit d7974ea

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

connection.go

+3-2
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,
@@ -1733,9 +1733,10 @@ func (conn *Connection) shutdown() {
17331733
conn.mutex.Lock()
17341734
defer conn.mutex.Unlock()
17351735

1736-
if !atomic.CompareAndSwapUint32(&(conn.state), connConnected, connShutdown) {
1736+
if !atomic.CompareAndSwapUint32(&conn.state, connConnected, connShutdown) {
17371737
return
17381738
}
1739+
17391740
conn.cond.Broadcast()
17401741
conn.notify(Shutdown)
17411742

0 commit comments

Comments
 (0)