Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pings never being sent #1461

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/src/libp2p/connection/established/single_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,14 @@ where
.unwrap()
.0
.queue_ping(&payload, read_write.now.clone() + self.inner.ping_timeout);
self.inner
.yamux
.mark_substream_write_ready(self.inner.outgoing_pings);
} else {
return Ok((self, Some(Event::PingOutFailed)));
}
}

// Only wake up if the connection can be closed.
// TODO: review w.r.t. https://github.com/smol-dot/smoldot/issues/1121
if read_write.expected_incoming_bytes.is_some()
&& read_write.write_bytes_queueable.is_some()
{
read_write.wake_up_after(&self.inner.next_ping);
}
read_write.wake_up_after(&self.inner.next_ping);

// If we have both sent and received a GoAway frame, that means that no new substream
// can be opened. If in addition to this there is no substream in the connection,
Expand All @@ -165,7 +161,13 @@ where
// to the remote that these new substreams are denied. However, this is not a problem
// as the remote interprets our GoAway frame as an automatic refusal of all its pending
// substream requests.
if self.inner.yamux.is_empty()
// TODO: review w.r.t. https://github.com/smol-dot/smoldot/issues/1121
if (self.inner.yamux.len()
== if self.inner.yamux.has_substream(self.inner.outgoing_pings) {
1
} else {
0
})
&& self.inner.yamux.goaway_sent()
&& self.inner.yamux.received_goaway().is_some()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/src/libp2p/connection/established/substream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ where
// We check the timeouts before checking the incoming data, as otherwise pings
// might succeed after their timeout.
for timeout in queued_pings.iter_mut() {
if timeout.as_ref().map_or(false, |t| *t < read_write.now) {
if timeout.as_ref().map_or(false, |t| *t <= read_write.now) {
*timeout = None;
read_write.wake_up_asap();
return (
Expand Down
1 change: 1 addition & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed

- Fix pings never being sent to peers, which means that smoldot would fail to detect when a connection is no longer responsive. ([#1461](https://github.com/smol-dot/smoldot/pull/1461))
- Fix connection being properly killed when the ping substream fails to be negotiated. ([#1459](https://github.com/smol-dot/smoldot/pull/1459))

## 2.0.13 - 2023-11-28
Expand Down
Loading