Clivern / Beaver

💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps.

Home Page:https://clivern.github.io/Beaver/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It panic error occasionally

SunDrizzle opened this issue · comments

Describe the bug
I use beaver to build a socket server.But sometimes it panics with an error.
The error is : fatal error: concurrent map writes.

And the error's stacks info : github.com/clivern/beaver/internal/app/controller.(*Websocket).HandleConnections(0xc0001ca4d0, 0x7f033e218240, 0xc0004869a0, 0xc0000b1200, 0xc000233108, 0x24, 0xc00023312d, 0xbd, 0xc000029440, 0x24) /root/Beaver/internal/app/controller/socket.go:166 +0x505 fp=0xc000585688 sp=0xc0005854e8 pc=0xabd815.

The code in 166 line is:delete(e.Clients, ID)

I google for the reason and find it's unsafe that using map in goruntine. So I think Websocket.Clients should protected by mutex or use sync.Map directly?

Development or production environment

  • OS: [Ubuntu 16.04]
  • Go 1.12.17
commented

it is unsafe indeed since may be it got concurrent edits at same time, will check that on code

here is where the issue happen https://github.com/Clivern/Beaver/blob/master/internal/app/controller/socket.go#L166