Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

server and client websocket closing #43

wants to merge 3 commits into from

Conversation

capturcus
Copy link
Owner

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

@capturcus capturcus requested review from piodul and mparafin April 15, 2021 23:50
server/websocket.cpp Outdated Show resolved Hide resolved
client/dfclient/src/websocket.cpp Outdated Show resolved Hide resolved
client/dfclient/src/websocket.cpp Outdated Show resolved Hide resolved
client/dfclient/src/websocket.cpp Outdated Show resolved Hide resolved
client/dfclient/src/util.cpp Outdated Show resolved Hide resolved
server/websocket.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@mparafin mparafin left a 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/websocket.cpp Outdated Show resolved Hide resolved
Comment on lines 96 to 97
int ret = webSocketManager._ws->Connect(gameData.serverAddress);
if (ret < 0) {
Copy link
Collaborator

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.

Copy link
Collaborator

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).

Copy link
Collaborator

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

Copy link
Owner Author

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.

client/dfclient/src/util.cpp Outdated Show resolved Hide resolved
client/dfclient/src/websocket.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants