Skip to content

Commit

Permalink
Fix pings never being sent (#1461)
Browse files Browse the repository at this point in the history
* Fix pings never being sent

* PR link

* Rustfmt
  • Loading branch information
tomaka authored Dec 11, 2023
1 parent fa7ef46 commit 8c1f5dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
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

0 comments on commit 8c1f5dd

Please sign in to comment.