diff --git a/v1/client/client.go b/v1/client/client.go index 201a52e..04d82b1 100644 --- a/v1/client/client.go +++ b/v1/client/client.go @@ -235,7 +235,10 @@ func (wsClient *SafeWebsocketClient) connect() error { pingCtx, pingCancel := context.WithCancel(context.Background()) go wsClient.startPingTicker(pingCtx) - wsClient.cancelFuncs = append(wsClient.cancelFuncs, pingCancel) + wsClient.mu.WriteHandler(func() error { + wsClient.cancelFuncs = append(wsClient.cancelFuncs, pingCancel) + return nil + }) if wsClient.conn != nil { wsClient.conn.Close() @@ -251,7 +254,10 @@ func (wsClient *SafeWebsocketClient) connect() error { go func() { ctx, cancel := context.WithCancel(context.Background()) - wsClient.cancelFuncs = append(wsClient.cancelFuncs, cancel) + wsClient.mu.WriteHandler(func() error { + wsClient.cancelFuncs = append(wsClient.cancelFuncs, cancel) + return nil + }) for { select { case <-ctx.Done(): @@ -285,7 +291,10 @@ func (wsClient *SafeWebsocketClient) connect() error { go func() { ctx, cancel := context.WithCancel(context.Background()) - wsClient.cancelFuncs = append(wsClient.cancelFuncs, cancel) + wsClient.mu.WriteHandler(func() error { + wsClient.cancelFuncs = append(wsClient.cancelFuncs, cancel) + return nil + }) for { select { case <-ctx.Done():