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
struct WorkQueue {
waiting: VecDeque<oneshot::Sender<Result<NngMsg>>>,
ready: VecDeque<Result<NngMsg>>,
}
impl WorkQueue {
fn push_back(&mut self, message: Result<NngMsg>) {
if let Some(sender) = self.waiting.pop_front() {
sender
.send(message)
.unwrap_or_else(|err| debug!("Dropping message: {:?}", err));
} else {
self.ready.push_back(message);
}
}
fn pop_front(&mut self) -> AsyncMsg {
// If a value is ready return it immediately. Otherwise
if let Some(item) = self.ready.pop_front() {
Box::pin(future::ready(item))
} else {
let (sender, receiver) = oneshot::channel();
self.waiting.push_back(sender);
let receiver = receiver.map(result::flatten_result);
Box::pin(receiver)
}
}
}
When you read from a socket. The pop_front function is called. Since there is no message ready, an oneshot channel is registered. If the read is cancelled (AsyncMsg is dropped), the oneshot stays registered.
Eventually, when a message actually is received, it will be sent to that invalid channel. The send will fail and the message will be dropped.
A simple workaround would be to put the body of the push_back within a loop statement. Trying to send the message until a valid channel is reached or until it is placed into the ready queue.
Cancelling a read is useful when you use the select! macro.
The text was updated successfully, but these errors were encountered:
From the source code:
When you read from a socket. The pop_front function is called. Since there is no message ready, an oneshot channel is registered. If the read is cancelled (AsyncMsg is dropped), the oneshot stays registered.
Eventually, when a message actually is received, it will be sent to that invalid channel. The send will fail and the message will be dropped.
A simple workaround would be to put the body of the push_back within a loop statement. Trying to send the message until a valid channel is reached or until it is placed into the ready queue.
Cancelling a read is useful when you use the
select!
macro.The text was updated successfully, but these errors were encountered: