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
When using the async code and the Sender sends and gets dropped at the wrong time, the Receiver won't receive the sent value. Here is how the race happens:
Let's have a Sendertx and a Receiverrx.
User calls rx.recv().await, the RecvFut::poll_inner func goes here. So far so good.
The next time RecvFut::poll_inner is called, we get to line 377 where we check whether the sender sent something already. At this point the sender has not and thus we do not proceed to the if block (line 378).
But now the sending thread is scheduled, the sender sends a value and tx is dropped.
The receiving thread wakes up inside RecvFut::poll_inner, on line 379 it determines that the Sender has been destroyed and Poll::Ready(Err(RecvError::Disconnected)) is returned without ever returning the value from the previous step.
I have a solution which I tested and seems to be working fine: instead of testing if self.receiver.shared.is_disconnected() on line 379 we can just check whether the returned value from step #3 is equal to Err(TryRecvTimeoutError::Disconnected). I'll send a PR.
The text was updated successfully, but these errors were encountered:
The race condition was happening when the Sender sent a value and was
immediatelly dropped between the calls
`self.receiver.shared.recv_sync(None)` and
`self.receiver.shared.is_disconnected()`. More information on github
issue zesterer#120
When using the
async
code and theSender
sends and gets dropped at the wrong time, theReceiver
won't receive the sent value. Here is how the race happens:Sender
tx
and aReceiver
rx
.rx.recv().await
, theRecvFut::poll_inner
func goes here. So far so good.RecvFut::poll_inner
is called, we get to line 377 where we check whether the sender sent something already. At this point the sender has not and thus we do not proceed to theif
block (line 378).tx
is dropped.RecvFut::poll_inner
, on line 379 it determines that theSender
has been destroyed andPoll::Ready(Err(RecvError::Disconnected))
is returned without ever returning the value from the previous step.I have a solution which I tested and seems to be working fine: instead of testing
if self.receiver.shared.is_disconnected()
on line 379 we can just check whether the returned value from step#3
is equal toErr(TryRecvTimeoutError::Disconnected)
. I'll send a PR.The text was updated successfully, but these errors were encountered: