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

Double Posting in Hall of Fame #27

Open
yutotakano opened this issue May 2, 2021 · 1 comment
Open

Double Posting in Hall of Fame #27

yutotakano opened this issue May 2, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@yutotakano
Copy link
Collaborator

Double posting in the Hall of Fame channel is becoming a very very frequent problem (1 in 2 at least), and I've been manually deleting many -- if it's a race condition, it's way too frequent and should be fixed immediately.

@yutotakano yutotakano added the bug Something isn't working label May 2, 2021
@jacobjwalters
Copy link
Collaborator

jacobjwalters commented May 4, 2021

This is indeed a race condition, and occurs due to the fact that each time we receive an event (in this case, a reaction being added), we spawn a new thread. These (non-atomically) read the entire db of HoF'd posts, check if the given post is in it, and if not prepends it and posts an entry in the HoF channel.

The issue here is that the file read and search operation is slow (and lazy), so if events come in fast enough we can effectively get a TOCTOU situation on our hands.

The best way I can immediately think of to solve this is to store a semaphore for the file in an MVar to ensure we can atomically check for the entry's existence in the db. It might be nice to provide this functionality in Utils such that it can be used elsewhere, as I imagine this type of bug could come up again. It seems that System.Posix.Semaphore provides it for any POSIX-compliant system (which we currently assume anyways), so that should be a nice solution. It automatically handles thread safety for us too!

This could also be mitigated by keeping a copy of the db in an MVar also (which I plan to implement with the config/db system rewrite).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants