The scenario is around remote fiber activation. And it goes like this:
A fiber is blocked on EventCount.wait_until (i.e. timed wait)
The fiber times outs but in parallel another thread sends it a notification via the remote queue.
EventCount::wait_until tries to pull itself from the remote queue, but does not find itself there, even though the notification was pushed STRICTLY BEFORE active->PullMyselfFromRemoteReadyQueue() call. We know it because the notify call is under the EventCount spinlock, and PullMyselfFromRemoteReadyQueue is done after the spinlock was grabbed and released.
The scenario happens when, the remote queue is empty but then something else tries to notify another, unrelated fiber in the thread, but does not finish crossing the blocking point (*). Then our fiber had notification being pushed into the queue. Then our fiber is waked by the timeout and it tries to pull itself from the queue just to learn the queue is empty, which contradicts the fact we observed BEFORE relationship between notify and PullMyselfFromRemoteReadyQueue call due to the spinlock in EventCount.
This fix recognizes the stuck in the middle push by loading the tail and comparing it with head.
The scenario is around remote fiber activation. And it goes like this:
active->PullMyselfFromRemoteReadyQueue()
call. We know it because the notify call is under the EventCount spinlock, and PullMyselfFromRemoteReadyQueue is done after the spinlock was grabbed and released.The scenario happens when, the remote queue is empty but then something else tries to notify another, unrelated fiber in the thread, but does not finish crossing the blocking point (*). Then our fiber had notification being pushed into the queue. Then our fiber is waked by the timeout and it tries to pull itself from the queue just to learn the queue is empty, which contradicts the fact we observed BEFORE relationship between notify and PullMyselfFromRemoteReadyQueue call due to the spinlock in EventCount.
This fix recognizes the stuck in the middle push by loading the tail and comparing it with head.