chirpstack / chirpstack-gateway-bridge

ChirpStack Gateway Bridge abstracts Packet Forwarder protocols into Protobuf or JSON over MQTT.
https://www.chirpstack.io
MIT License
423 stars 272 forks source link

basic-station: concurrent write to websocket connection #191

Closed fancar closed 3 years ago

fancar commented 3 years ago

Hello Brocaar! Recently I faced the issue. It happens when a gateway is under heavy load (~250-300 messages per min)

panic: concurrent write to websocket connection

goroutine 96544 [running]: github.com/gorilla/websocket.(messageWriter).flushFrame(0x2ab1724, 0x1, 0x0, 0x0, 0x0, 0xf14ee1ea, 0x52d33c) /home/fancar/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go:610 +0x590 github.com/gorilla/websocket.(Conn).WriteMessage(0x28a69c0, 0x9, 0x0, 0x0, 0x0, 0x3b9aca00, 0x0) /home/fancar/go/pkg/mod/github.com/gorilla/websocket@v1.4.2/conn.go:763 +0x1c8 github.com/brocaar/chirpstack-gateway-bridge/internal/backend/basicstation.(Backend).websocketWrap.func2(0x2955340, 0x28a69c0, 0x28948c0, 0x2ab6340) /home/fancar/dev/iot/chirp/chirpstack-gateway-bridge/internal/backend/basicstation/backend.go:833 +0x18c created by github.com/brocaar/chirpstack-gateway-bridge/internal/backend/basicstation.(Backend).websocketWrap /home/fancar/dev/iot/chirp/chirpstack-gateway-bridge/internal/backend/basicstation/backend.go:827 +0x240

brocaar commented 3 years ago

Hi @fancar any reason why you closed the PR? Is it because your solution did not fix the issue, or is the issue no longer valid?

brocaar commented 3 years ago

@fancar I believe the above commit should fix the issue.

fancar commented 3 years ago

I closed it because It didn't pass the test. You can check the last commit in the same branch of fork tho. It works for me. Thank you for your solution.

ps There is some memory leak problem I faced too. I'll send a new pull request as soon as I catch it.