How do I debug a tokio hang? (tokio-0.3.3)

If there is data available in the stream and you clear the readiness flag, then the next call to poll_read_ready will return Pending regardless of whether or not there is data in the stream, until even more data arrives.

1 Like

Thanks for the clarification.

One thought I have is that if you cleared the readiness flag first, then read the data, then the race condition wouldn't happen because if data arrives while reading the data, then it arrived after clearing the flag.

But I don't know enough details to say for sure whether this would work.

1 Like

I think this makes a lot of sense, thanks for the suggestion. I will update my code to do this even though I only use read now (I call it in a loop until it fails with EWOULDBLOCK). I think there may be a race still between I get EWOULDBLOCK and clear the readiness state currently, which your suggestion fixes.