Skip to content

Commit 60e32c9

Browse files
authored
fix(ping): Fix panic in WASM caused by retrying on dial upgrade errors
This PR workarounds async-rs/futures-timer#74 issue. Fixes #5442 Pull-Request: #5447.
1 parent 75483e8 commit 60e32c9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

protocols/ping/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
- Use `web-time` instead of `instant`.
44
See [PR 5347](https://github.com/libp2p/rust-libp2p/pull/5347).
55

6+
- Fix panic in WASM caused by retrying on dial upgrade errors.
7+
See [PR 5447](https://github.com/libp2p/rust-libp2p/pull/5447).
8+
69
## 0.44.1
710

811
- Impose `Sync` on `ping::Failure::Other`.

protocols/ping/src/handler.rs

+12
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ impl Handler {
184184
) {
185185
self.outbound = None; // Request a new substream on the next `poll`.
186186

187+
// Timer is already polled and expired before substream request is initiated
188+
// and will be polled again later on in our `poll` because we reset `self.outbound`.
189+
//
190+
// `futures-timer` allows an expired timer to be polled again and returns
191+
// immediately `Poll::Ready`. However in its WASM implementation there is
192+
// a bug that causes the expired timer to panic.
193+
// This is a workaround until a proper fix is merged and released.
194+
// See libp2p/rust-libp2p#5447 for more info.
195+
//
196+
// TODO: remove when async-rs/futures-timer#74 gets merged.
197+
self.interval.reset(Duration::new(0, 0));
198+
187199
let error = match error {
188200
StreamUpgradeError::NegotiationFailed => {
189201
debug_assert_eq!(self.state, State::Active);

0 commit comments

Comments
 (0)