Compare commits

...

1 Commits

Author SHA1 Message Date
c550701dfa fix: adding lock for cancel function slices 2025-09-29 22:53:29 +07:00

View File

@@ -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():