Skip to content

Panic: concurrent write to websocket connection when sending WebSocket events (0.7.2) #99

Description

@tuGusz

Welcome!

  • Yes, I have searched for similar issues on GitHub and found none.

What did you do?

O erro ocorreu durante a utilização normal da EvolutionGo
A aplicação estava conectada ao WhatsApp e processando eventos normalmente quando, em determinado momento, ocorreu um panic que encerrou completamente o processo.
Eu consegui identificar um passo exato para reproduzir o problema de forma consistente, ele ocorreu durante o processamento simultâneo de eventos. Principalmente quando estamos recebendo muita mensagem e lendo mensagem.
Mas identifiquei que quando usamos o evento para restaurar o histórico de conversas, caso ultrapasse mais de 50 mensagens de acordo com os logs, ele da Panic e encerra e todas as instancias são desconectadas

Pelo stack trace, o panic acontece dentro de websocketProducer.Produce(), durante a chamada de WriteJSON() da biblioteca Gorilla WebSocket.

What did you expect?

Esperava que a aplicação continuasse processando e enviando os eventos normalmente, sem encerrar o processo.
Mesmo com múltiplos eventos sendo processados ao mesmo tempo, a escrita na conexão WebSocket deveria ser sincronizada para evitar concorrência.

What did you observe instead of what you expected?

A aplicação encerra com o seguinte panic:

panic: concurrent write to websocket connection

O stack trace indica que múltiplas goroutines estão tentando escrever simultaneamente na mesma conexão WebSocket, resultando no encerramento da EvolutionGo.

Stack trace:

panic: concurrent write to websocket connection

goroutine 969 [running]:
github.com/gorilla/websocket.(*messageWriter).flushFrame(0xc0013019e0, 0x1, {0x0?, 0x47c305?, 0x30?})
        /go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:617 +0x4af
github.com/gorilla/websocket.(*messageWriter).Close(0x7453cc47d201?)
        /go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:731 +0x35
github.com/gorilla/websocket.(*Conn).beginMessage(0xc0017329a0, 0xc00158d800, 0x1)
        /go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:480 +0x37
github.com/gorilla/websocket.(*Conn).NextWriter(0xc0017329a0, 0x1)
        /go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:520 +0x3f
github.com/gorilla/websocket.(*Conn).WriteJSON(0x171ece0?, {0x171ece0, 0xc00158d7d0})
        /go/pkg/mod/github.com/gorilla/websocket@v1.5.3/json.go:24 +0x34
github.com/evolution-foundation/evolution-go/pkg/events/websocket.(*websocketProducer).Produce(0xc000590d00, {0xc0013e4db0, 0x2c}, {0xc0011c0480, 0x206, 0xc0016b9dd0?}, {0xc00004dc20, 0x24}, {0xc00004dc50, 0x24})
        /build/pkg/events/websocket/websocket_producer.go:127 +0x42a
github.com/evolution-foundation/evolution-go/pkg/whatsmeow/service.(*whatsmeowService).sendToQueueOrWebhook(0xc0001fce10, 0xc000176a00, {0xc0013e4db0, 0x2c}, {0xc0011c0480, 0x206, 0x240})
        /build/pkg/whatsmeow/service/whatsmeow.go:2305 +0x4f9
github.com/evolution-foundation/evolution-go/pkg/whatsmeow/service.(*whatsmeowService).CallWebhook(0xc0001fce10, 0xc000176a00, {0xc0013e4db0, 0x2c}, {0xc0011c0480, 0x206, 0x240})
        /build/pkg/whatsmeow/service/whatsmeow.go:2191 +0x242b
created by github.com/evolution-foundation/evolution-go/pkg/whatsmeow/service.(*MyClient).myEventHandler in goroutine 967
        /build/pkg/whatsmeow/service/whatsmeow.go:2098 +0x997e
...

Screenshots/Videos

No response

Which version are you using?

0.7.2

What is your environment?

Linux

If applicable, paste the log output

Sistema Operacional: Linux
Implantação: Docker
WebSocket: Habilitado
2026/07/03 09:31:20 [INFO] [] subscriptions [MESSAGE SEND_MESSAGE READ_RECEIPT PRESENCE HISTORY_SYNC CHAT_PRESENCE CALL CONNECTION LABEL CONTACT GROUP NEWSLETTER QRCODE BUTTON_CLICK] eventType Receipt
2026/07/03 09:31:20 [INFO] [] Event received of type Receipt
panic: concurrent write to websocket connection

goroutine 969 [running]:
github.com/gorilla/websocket.(*messageWriter).flushFrame(0xc0013019e0, 0x1, {0x0?, 0x47c305?, 0x30?})
/go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:617 +0x4af
github.com/gorilla/websocket.(*messageWriter).Close(0x7453cc47d201?)
/go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:731 +0x35
github.com/gorilla/websocket.(*Conn).beginMessage(0xc0017329a0, 0xc00158d800, 0x1)
/go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:480 +0x37
github.com/gorilla/websocket.(*Conn).NextWriter(0xc0017329a0, 0x1)
/go/pkg/mod/github.com/gorilla/websocket@v1.5.3/conn.go:520 +0x3f
github.com/gorilla/websocket.(*Conn).WriteJSON(0x171ece0?, {0x171ece0, 0xc00158d7d0})
/go/pkg/mod/github.com/gorilla/websocket@v1.5.3/json.go:24 +0x34
github.com/evolution-foundation/evolution-go/pkg/events/websocket.(*websocketProducer).Produce(0xc000590d00, {0xc0013e4db0, 0x2c}, {0xc0011c0480, 0x206, 0xc0016b9dd0?}, {0xc00004dc20, 0x24}, {0xc00004dc50, 0x24})
/build/pkg/events/websocket/websocket_producer.go:127 +0x42a
github.com/evolution-foundation/evolution-go/pkg/whatsmeow/service.(*whatsmeowService).sendToQueueOrWebhook(0xc0001fce10, 0xc000176a00, {0xc0013e4db0, 0x2c}, {0xc0011c0480, 0x206, 0x240})
/build/pkg/whatsmeow/service/whatsmeow.go:2305 +0x4f9
github.com/evolution-foundation/evolution-go/pkg/whatsmeow/service.(*whatsmeowService).CallWebhook(0xc0001fce10, 0xc000176a00, {0xc0013e4db0, 0x2c}, {0xc0011c0480, 0x206, 0x240})
/build/pkg/whatsmeow/service/whatsmeow.go:2191 +0x242b
created by github.com/evolution-foundation/evolution-go/pkg/whatsmeow/service.(*MyClient).myEventHandler in goroutine 967
/build/pkg/whatsmeow/service/whatsmeow.go:2098 +0x997e

Additional Notes

Na versão 0.7.0 isso não ocorria

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions