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

In chat example, two users can kick each other #29

Open
shiraeeshi opened this issue Mar 23, 2021 · 2 comments
Open

In chat example, two users can kick each other #29

shiraeeshi opened this issue Mar 23, 2021 · 2 comments

Comments

@shiraeeshi
Copy link

In chat example from Chapter 12, it seems to me that there is no guarantee that when two users kick each other at the same time, only one of the kicks will succeed.
The kick operation is divided to two STM transactions (two atomically calls): one of them is in server function in runClient (at line 214), the second one is in handleMessage (at line 236). When we divide the transaction into two, we lose the atomicity, right?
Here is an example project (https://github.com/shiraeeshi/hs-parconc-chat-server) that shows how to make two concurrent kicks succeed. I added /pause, /resume, /pauseKicks, /resumeKicks commands. You can see the scenario in readme.

@shiraeeshi
Copy link
Author

You can see the changes in this commit diff.

@simonmar
Copy link
Owner

simonmar commented Apr 2, 2021

Yes, I think you're right. To fix this, either the two transactions should be combined, or the kick function should check that the current user has not already been kicked.

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

No branches or pull requests

2 participants