Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Server host's client sometimes crashes when another client connects #1007

Open
ianling opened this issue Dec 26, 2020 · 1 comment
Open

Server host's client sometimes crashes when another client connects #1007

ianling opened this issue Dec 26, 2020 · 1 comment

Comments

@ianling
Copy link
Contributor

ianling commented Dec 26, 2020

Describe the bug
The host's game can crash when another client connects due to the renderer reading from the map of entities at the same time that the new player is added to that map. In other words, two goroutines are accessing one map at the same time.

[Game Server][INFO] Accepting connection: 127.0.0.1:38860

[Game Server][INFO] Client connected with an id of cf9b10b7-654e-48d5-aeed-8c1d69733898
fatal error: concurrent map iteration and map write
[... stack trace...]

The two functions trying to read and write the map at the same time are:

  • d2core/d2map/d2maprenderer/renderer.go:244 (for _, mapEntity := range mr.mapEngine.Entities() {)
  • d2networking/d2client/game_client.go:227 (g.MapEngine.AddEntity(newPlayer))

There is some other code that writes to this map as well, so whoever picks this up should consider implementing a fix that handles all cases, not just this one.

To Reproduce
Steps to reproduce the behavior:

  1. Start two clients.
  2. On one client, host a multiplayer game
  3. Join the game on the other client
  4. The host's game may crash (doesn't happen every time, race condition)

Expected behavior
The second client joins the host's game successfully, no one crashes

Desktop (please complete the following information):

  • OS: Xubuntu 20.04 x86_64

Not sure what the best solution would be here. Maybe reading the list of entities should happen from a copy of the map and not from a pointer?

@essial
Copy link
Member

essial commented Dec 27, 2020

If data is being written or read to via a thread, we've gotta make sure those actions are thread safe. Not just for this, but for anything in the codebase.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants