You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ProcessWaiting replies to the newest waiting request but pops the oldest #34
TRequestProcessor::ProcessWaiting uses std::queue, whose back() is the newest element and whose pop() removes the oldest (front). The loop checks and replies using Waiting.back() but pops the front (raft.cpp#L650-L651). The strong-read loop has the same mismatch with StrongWaiting (raft.cpp#L670-L671).
Scenario
Writes at indexes 5 and 6 are waiting from two clients, and both become applied in one pass. The first iteration looks at back() (index 6), copies it as w, pops the front (index 5), and replies to the client of index 6 using the answer found for index 6 (the answer for index 5 is dropped by the WriteAnswers cleanup loop). The second iteration sees back() still being index 6 (the queue still holds that entry), so it runs again for index 6: WriteAnswers is now empty, so assert(!WriteAnswers.empty()) fires (in a build with NDEBUG it is undefined behaviour on front() of an empty queue). The client of index 5 never gets a reply. For reads there is no assert: the newest read is answered several times and the older ones never. With a single waiting entry the code works, which is why it is hard to notice.
Expected
Waiting requests complete in FIFO order: check front(), reply to it, and pop it, for both Waiting and StrongWaiting. Each request gets exactly one reply.
PR #31 (closed, not merged) fixes it in 76aae7a (front/pop for both queues). Tests that cover it: test_read_fifo, test_strong_read_fifo, test_write_fifo, test_partial_write_completion. Since the PR is closed, the fix would come as a separate small PR.
Activity