node: Always notify the service of a fetch result

Even if the peer is no longer connected.
This commit is contained in:
cloudhead 2024-04-09 15:09:20 +02:00
parent 395d317954
commit 53ecc88437
No known key found for this signature in database
1 changed files with 21 additions and 21 deletions

View File

@ -409,16 +409,10 @@ where
return;
};
let Peer::Connected {
nid, link, streams, ..
} = peer
else {
log::warn!(target: "wire", "Peer {nid} is not connected; ignoring fetch result");
return;
};
// Nb. It's possible that the stream would already be unregistered if we received an early
// "close" from the remote. Otherwise, we unregister it here and send the "close" ourselves.
if let Peer::Connected { link, streams, .. } = peer {
// Nb. It's possible that the stream would already be unregistered if we received an
// early "close" from the remote. Otherwise, we unregister it here and send the "close"
// ourselves.
if let Some(s) = streams.unregister(&task.stream) {
log::debug!(
target: "wire", "Stream {} of {} closing with {} byte(s) sent and {} byte(s) received",
@ -432,11 +426,17 @@ where
);
self.actions.push_back(Action::Send(fd, frame.to_bytes()));
}
} else {
// If the peer disconnected, we'll get here, but we still want to let the service know
// about the fetch result, so we don't return here.
log::warn!(target: "wire", "Peer {nid} is not connected; ignoring fetch result");
return;
};
// Only call into the service if we initiated this fetch.
match task.result {
FetchResult::Initiator { rid, result } => {
self.service.fetched(rid, *nid, result);
self.service.fetched(rid, nid, result);
}
FetchResult::Responder { rid, result } => {
if let Some(rid) = rid {