johnmpost / insight

insight is a lightweight, minimalist polling app for power users
https://insight.johnpost.xyz
MIT License
0 stars 0 forks source link

bug fix: fix race condition about active questions on join #3

Open johnmpost opened 1 year ago

johnmpost commented 1 year ago

Problem:

Proposed Solution: To address this race condition, we propose implementing a locking mechanism on the server-side to ensure that the state of the active question is consistent between the HTTP request from the participant and any changes made by the host. This can be achieved by acquiring a lock on accesses and updates to the state of the active question in relevant route handlers.

For example, in the route handler for the HTTP request from the participant to check for an active question, a lock could be acquired before checking its state and sending a websocket message to the participant if necessary. Once the websocket message has been sent (or not sent if there is no active question), the lock could be released.

This would ensure that any changes to the state of the active question made by the host (such as ending an active question) would only occur after the participant has received a response to their HTTP request. In other words, while a lock is held on accesses and updates to the state of the active question, any attempts by the host to end an active question would be blocked until after the lock is released.

johnmpost commented 1 year ago

there's an extremely small time window in which this race condition could occur, and as such is highly improbable. Therefore, it's not a priority. but technically it could happen