This is only used by the test suite, but it can cause tests to randomly fail, which is a problem.
The issue is the lack of synchronization between the stored waker and the state of the cursor.
There are a few possible fixes:
- Use a single lock around the entire cursor state, instead of per-field locks.
- Store the waker before performing any operation which might block, or at least re-check if the operation can succeed after storing the waker.
- Look for a prebuilt solution, it seems like something like this should exist in
futures or elsewhere.