fix connection lock call

This commit is contained in:
c9s 2021-05-30 18:14:22 +08:00
parent 69e76485c5
commit 0b935eff4f
2 changed files with 6 additions and 4 deletions

View File

@ -326,6 +326,9 @@ func (s *Stream) connect(ctx context.Context) error {
log.Infof("listen key is created: %s", MaskKey(listenKey))
}
// should only start one connection one time, so we lock the mutex
s.ConnLock.Lock()
// when in public mode, the listen key is an empty string
conn, err := s.dial(listenKey)
if err != nil {
@ -334,8 +337,6 @@ func (s *Stream) connect(ctx context.Context) error {
log.Infof("websocket connected")
// should only start one connection one time, so we lock the mutex
s.ConnLock.Lock()
// ensure the previous context is cancelled
if s.connCancel != nil {

View File

@ -241,6 +241,9 @@ func (s *Stream) connect(ctx context.Context) error {
url = okexapi.PrivateWebSocketURL
}
// should only start one connection one time, so we lock the mutex
s.connLock.Lock()
conn, err := s.StandardStream.Dial(url)
if err != nil {
return err
@ -248,8 +251,6 @@ func (s *Stream) connect(ctx context.Context) error {
log.Infof("websocket connected: %s", url)
// should only start one connection one time, so we lock the mutex
s.connLock.Lock()
// ensure the previous context is cancelled
if s.connCancel != nil {