Closed menonsamir closed 1 year ago
Someone is attempting to deploy a commit to a Personal Account owned by @cmnord on Vercel.
@cmnord first needs to authorize it.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
jep | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Aug 21, 2023 4:36am |
Currently, when two players exactly tie (in milliseconds) on a buzz, their clients can end up in a state where each client believes it has won the buzz.
In the
getWinningBuzzer
function, we iterate through thebuzzes
map to find a winner. Since JavaScriptMap
's iterate in insertion order, this can create a local client-dependent ordering onbuzzes
. In the case of a tie, when we reduce to find the minimumdelayMs
time, this order will decided the winner.The fix in this PR orders the iteration through the entries of
buzzes
byuserId
prior to searching for a minimum delay. This ensures that the user with a loweruserId
wins ties, making all clients determine the same winner each time.This slightly suboptimal; we'd prefer that each tie get resolved randomly (so that no one player has an advantage). However, ties are rare in the first place, and I'd suggest a more robust solution is to use
performance.now()
instead ofDate.now()
, which would yield sub-millisecond accuracy that would make ties very unlikely. I'll leave that fix for a later PR.