Skip to content

Commit 7e01125

Browse files
fix types
1 parent ee2d1d8 commit 7e01125

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

connection.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const (
2828
connClosed = 2
2929
)
3030

31+
const (
32+
shutdownNotInProgress = 0
33+
shutdownInProgress = 1
34+
)
35+
3136
const (
3237
connTransportNone = ""
3338
connTransportSsl = "ssl"
@@ -163,10 +168,9 @@ type Connection struct {
163168
// watchMap is a map of key -> chan watchState.
164169
watchMap sync.Map
165170

166-
// shutdownOn is true if shutdown is processed now.
167-
shutdownOn atomic.Bool
168-
shutdownWatcher Watcher
169-
shutdownWg sync.WaitGroup
171+
shutdownInProgress uint32
172+
shutdownWatcher Watcher
173+
shutdownWg sync.WaitGroup
170174
}
171175

172176
var _ = Connector(&Connection{}) // Check compatibility with connector interface.
@@ -390,7 +394,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
390394
conn.opts.Logger = defaultLogger{}
391395
}
392396

393-
conn.shutdownOn.Store(false)
397+
atomic.StoreUint32(&(conn.shutdownInProgress), shutdownNotInProgress)
394398

395399
if err = conn.createConnection(false); err != nil {
396400
ter, ok := err.(Error)
@@ -456,8 +460,8 @@ func (conn *Connection) shutdownOnServerEvent() {
456460
conn.mutex.Lock()
457461

458462
fmt.Printf("starting shutdown... (%v)\n", conn.UniqueId())
459-
conn.shutdownOn.Store(true)
460-
defer conn.shutdownOn.Store(false)
463+
atomic.StoreUint32(&(conn.shutdownInProgress), shutdownInProgress)
464+
defer atomic.StoreUint32(&(conn.shutdownInProgress), shutdownNotInProgress)
461465

462466
fmt.Printf("wait for futures to finish... (%v)\n", conn.UniqueId())
463467
conn.shutdownWg.Wait()
@@ -1167,7 +1171,7 @@ func (conn *Connection) send(req Request, streamId uint64) *Future {
11671171
}
11681172
}
11691173

1170-
if conn.shutdownOn.Load() {
1174+
if atomic.LoadUint32(&(conn.shutdownInProgress)) == shutdownInProgress {
11711175
conn.cancelFuture(fut, fmt.Errorf("instance shutdown in process"))
11721176
return fut
11731177
}

0 commit comments

Comments
 (0)