OpenFactorioServerManager / factorio-server-manager

A tool to help manage Factorio multiplayer servers including mods and save games.
MIT License
561 stars 135 forks source link

Race condition / concurrent access to map in websocket code #220

Closed knoxfighter closed 3 years ago

knoxfighter commented 3 years ago

GO doesn't allow concurrent access to maps. That is what happens in wshub:192 (*wsRoom.run()).

Basically, when rooms close themselves, they access the rooms map on the hub, which all rooms can at the same time.

fatal error: concurrent map writes
fatal error: concurrent map writes

goroutine 850 [running]:
runtime.throw(0x990edb, 0x15)
        /opt/hostedtoolcache/go/1.14.13/x64/src/runtime/panic.go:1116 +0x72 fp=0xc0001859d8 sp=0xc0001859a8 pc=0x434d82
runtime.mapdelete_faststr(0x8fa4c0, 0xc0000a3950, 0xc0002100d8, 0x7)
        /opt/hostedtoolcache/go/1.14.13/x64/src/runtime/map_faststr.go:377 +0x34c fp=0xc000185a40 sp=0xc0001859d8 pc=0x414e4c
github.com/mroote/factorio-server-manager/api/websocket.(*wsRoom).run(0xc0001a2180)
        /home/runner/work/factorio-server-manager/factorio-server-manager/src/api/websocket/wshub.go:192 +0x5e8 fp=0xc000185fd8 sp=0xc000185a40 pc=0x855498
runtime.goexit()
        /opt/hostedtoolcache/go/1.14.13/x64/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc000185fe0 sp=0xc000185fd8 pc=0x464471
created by github.com/mroote/factorio-server-manager/api/websocket.(*wsHub).GetRoom
        /home/runner/work/factorio-server-manager/factorio-server-manager/src/api/websocket/wshub.go:165 +0x19a