pinano-discord / Pinano-Discord-Bot

A Discord bot for the Pinano guild
MIT License
9 stars 11 forks source link

Add setup information, add async-mutex to package.json #68

Closed wesen closed 4 years ago

wesen commented 5 years ago

I was missing the async-mutex package.

The instructions are not entirely complete yet, I haven't entirely figured out how to setup the practice room channels.

pianiststickman commented 5 years ago

Actually, I suspect we'll soon be able to remove async-mutex entirely.

The reason we have async-mutex is because of bug #46, a possible race condition in the VC-autocreation code. The way we add rooms is to read the doc from the DB, push the new room into the array, then write the whole doc back into the DB. If the voiceStateChanged handler triggers twice in quick succession, one handler may read the list of rooms between when the other handler reads the list and when it writes it back to the DB with the new room - thus squashing that new room when the second handler writes its list back to the DB. My solution to this was to slap a mutex on the entire event handler, which met with limited success due to asynchronicity (though we haven't seen it for a while).

As it turns out the correct solution is probably to stop using db.collections.update() (which, per Mongo's warnings, are deprecated) and instead use db.collections.updateOne(), which contains an $addToSet atomic operator that seems like it was designed for precisely our purposes.

sit commented 4 years ago

Proposed changes have been superseded by other fixes.