ajanata / PretendYoureXyzzy

A web clone of the card game Cards Against Humanity.
https://pretendyoure.xyz/zy
BSD 2-Clause "Simplified" License
1.24k stars 396 forks source link

User: use a stably-ordered queue for long-polling #234

Open mokomull opened 4 years ago

mokomull commented 4 years ago

If the AJAX request for LongPollServlet happens with enough of a delay, there may be two stateful messages in the queue -- I have observed two GAME_STATE_CHANGE messages enqueued simultaneously when the Card Czar does not long-poll while the other players progress the game through PLAYING to JUDGING. The JS code overwrites the state as it iterates the list, so the "last state wins". But PriorityQueue explicitly does not guarantee any particular ordering among elements that compare "equal", causing the client to think the game is PLAYING.

Testing done

This avoids one flavor of error in a local client I'm developing, but to be honest, I'm still not finished debugging all of the other state-machine issues that it had.

ajanata commented 4 years ago

yeah I don't think there's really much of a point to having a priority to the messages... it was a good idea but perhaps a bit premature and wasn't useful. heck the entire MessageType can probably be removed, since its point was to prioritize messages in this queue