@@ -28,6 +28,11 @@ const (
28
28
connClosed = 2
29
29
)
30
30
31
+ const (
32
+ shutdownNotInProgress = 0
33
+ shutdownInProgress = 1
34
+ )
35
+
31
36
const (
32
37
connTransportNone = ""
33
38
connTransportSsl = "ssl"
@@ -163,10 +168,9 @@ type Connection struct {
163
168
// watchMap is a map of key -> chan watchState.
164
169
watchMap sync.Map
165
170
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
170
174
}
171
175
172
176
var _ = Connector (& Connection {}) // Check compatibility with connector interface.
@@ -390,7 +394,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
390
394
conn .opts .Logger = defaultLogger {}
391
395
}
392
396
393
- conn . shutdownOn . Store ( false )
397
+ atomic . StoreUint32 ( & ( conn . shutdownInProgress ), shutdownNotInProgress )
394
398
395
399
if err = conn .createConnection (false ); err != nil {
396
400
ter , ok := err .(Error )
@@ -456,8 +460,8 @@ func (conn *Connection) shutdownOnServerEvent() {
456
460
conn .mutex .Lock ()
457
461
458
462
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 )
461
465
462
466
fmt .Printf ("wait for futures to finish... (%v)\n " , conn .UniqueId ())
463
467
conn .shutdownWg .Wait ()
@@ -1167,7 +1171,7 @@ func (conn *Connection) send(req Request, streamId uint64) *Future {
1167
1171
}
1168
1172
}
1169
1173
1170
- if conn . shutdownOn . Load () {
1174
+ if atomic . LoadUint32 ( & ( conn . shutdownInProgress )) == shutdownInProgress {
1171
1175
conn .cancelFuture (fut , fmt .Errorf ("instance shutdown in process" ))
1172
1176
return fut
1173
1177
}
0 commit comments