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
I'm creating a AsyncWrite + AsyncRead wrapper around a custom socket implementation. I'm now facing the problem of race conditions around using SetReadiness.
It calls my implementation of read. The implementation determined it is going to return ErrorKind::WouldBlock.
In the meantime, another thread disconnects the socket. It calls set_readiness(Ready::all()).
The readiness flag is cleared again when read returns.
Normally, when my custom socket disconnects it will call set_readiness(Ready::all()). The function awaiting a read will then try to read but discovers that the socket is disconnected. In this case the code hangs because the poll_read implementation at https://github.com/tokio-rs/tokio/blob/tokio-0.2.22/tokio/src/io/poll_evented.rs#L391 has cleared the readiness flag.
What is the best way to deal with this situation? Shoudn't poll_read clear the readable flag before it calls read and after read is done set the flag again when the result isn't WouldBlock?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm creating a AsyncWrite + AsyncRead wrapper around a custom socket implementation. I'm now facing the problem of race conditions around using SetReadiness.
The following is going on:
read
. The implementation determined it is going to returnErrorKind::WouldBlock
.set_readiness(Ready::all())
.read
returns.Normally, when my custom socket disconnects it will call
set_readiness(Ready::all())
. The function awaiting a read will then try to read but discovers that the socket is disconnected. In this case the code hangs because thepoll_read
implementation at https://github.com/tokio-rs/tokio/blob/tokio-0.2.22/tokio/src/io/poll_evented.rs#L391 has cleared the readiness flag.What is the best way to deal with this situation? Shoudn't
poll_read
clear the readable flag before it callsread
and afterread
is done set the flag again when the result isn'tWouldBlock
?cc @carllerche
Beta Was this translation helpful? Give feedback.
All reactions