-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server and client websocket closing #43
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the race, seems to be working quite ok. The code itself is a bit messy, but it works - I think that a refactor would be in order, but that's a different task pretty far in the backlog. After resolving the race (and considering piodul's remarks) lgtm.
client/dfclient/src/menu_state.cpp
Outdated
int ret = webSocketManager._ws->Connect(gameData.serverAddress); | ||
if (ret < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The race is here - adding sleep(100ms)
after Connect()
seemed to solve the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use proper synchronization to fix it, though (e.g. mutexes, condition variables, semaphores).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piodul Don't get me wrong, it was just a note to pinpoint the problem, not a fix suggestion xD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to my research the race should not be present, even though I did nothing in the code to mitigate it. After the call to handshake
finished successfully the socket should be immediately available to send data. The only thing that might be racing here is if there is something happening within ioc.run
that makes the websocket ready to send messages and there is no way to synchronize anything within an external function call except for a sleep
.
After some testing I have not observed the race happening on my machine. It is possible that the racing behaviour was introduced in a different PR.
this makes repeated connections to a game that is already in progress handle nicely
there still is a race somewhere but I've seen it only once so it cannot be that bad