mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
binance: check connCancel only when new context is allocated
This commit is contained in:
parent
f9d4068145
commit
d112dbb1a4
|
@ -300,11 +300,6 @@ func (s *Stream) reconnector(ctx context.Context) {
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-s.ReconnectC:
|
case <-s.ReconnectC:
|
||||||
// ensure the previous context is cancelled
|
|
||||||
if s.connCancel != nil {
|
|
||||||
s.connCancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Warnf("received reconnect signal, reconnecting...")
|
log.Warnf("received reconnect signal, reconnecting...")
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
@ -342,6 +337,11 @@ func (s *Stream) connect(ctx context.Context) error {
|
||||||
// should only start one connection one time, so we lock the mutex
|
// should only start one connection one time, so we lock the mutex
|
||||||
s.ConnLock.Lock()
|
s.ConnLock.Lock()
|
||||||
|
|
||||||
|
// ensure the previous context is cancelled
|
||||||
|
if s.connCancel != nil {
|
||||||
|
s.connCancel()
|
||||||
|
}
|
||||||
|
|
||||||
// create a new context
|
// create a new context
|
||||||
s.connCtx, s.connCancel = context.WithCancel(ctx)
|
s.connCtx, s.connCancel = context.WithCancel(ctx)
|
||||||
conn.SetReadDeadline(time.Now().Add(readTimeout))
|
conn.SetReadDeadline(time.Now().Add(readTimeout))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user