Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(pubsub): drop tokio/time from the wasm build (#4023)#4027

Open
0xMars42 wants to merge 1 commit into
alloy-rs:mainfrom
0xMars42:fix/tokio-stream-no-default
Open

fix(pubsub): drop tokio/time from the wasm build (#4023)#4027
0xMars42 wants to merge 1 commit into
alloy-rs:mainfrom
0xMars42:fix/tokio-stream-no-default

Conversation

@0xMars42

@0xMars42 0xMars42 commented Jun 7, 2026

Copy link
Copy Markdown

Motivation

alloy-provider with the ws feature pulls tokio with the time feature on
wasm32-unknown-unknown. tokio/time panics at runtime when a tokio Runtime is built there, so a
wasm app using alloy-provider/ws crashes (#4023).

Root cause

Two paths enable tokio/time in the wasm build:

  1. tokio-stream's default features include time (time = ["tokio/time"]), and alloy-pubsub
    pulls tokio-stream. This is the path shown in the issue's cargo tree.
  2. alloy-pubsub's handle.rs imports tokio::time::Duration. The tokio::time module path
    requires the time feature, even though Duration itself is just std::time::Duration.

Fix

  1. Set default-features = false on the workspace tokio-stream (alloy-pubsub only uses its sync
    feature).
  2. Import std::time::Duration instead of tokio::time::Duration in alloy-pubsub.

alloy-pubsub already uses wasmtimer::tokio::sleep on wasm and tokio::time::sleep off-wasm, and
gets tokio/time on native via alloy-transport, so this only drops the feature from the wasm
target.

Verification

  • tokio/time is no longer pulled into the wasm build:
    cargo tree -e features -i tokio -p alloy-provider --features ws --target wasm32-unknown-unknown
    goes from 3 matches to 0 with this change.
  • alloy-provider with ws compiles for wasm32-unknown-unknown (the issue's scenario), and the
    repo's wasm-unknown CI job (cargo hack build --features ws --target wasm32-unknown-unknown,
    same excludes) builds clean locally.
  • Native build of alloy-pubsub is unaffected (tokio/time comes from alloy-transport).

Closes #4023.

@github-project-automation github-project-automation Bot moved this to Reviewed in Alloy Jun 7, 2026
@DaniPopes DaniPopes enabled auto-merge (squash) June 7, 2026 13:36
@DaniPopes DaniPopes disabled auto-merge June 7, 2026 13:39
@0xMars42 0xMars42 changed the title fix(deps): drop tokio/time on wasm by disabling tokio-stream default features fix(pubsub): drop tokio/time from the wasm build (#4023) Jun 7, 2026
@0xMars42 0xMars42 force-pushed the fix/tokio-stream-no-default branch from 63c9c1e to 1cc45cd Compare June 7, 2026 18:28
@0xMars42

0xMars42 commented Jun 7, 2026

Copy link
Copy Markdown
Author

Updated. The first version was incomplete: alloy-pubsub also imported tokio::time::Duration in handle.rs, which kept tokio/time enabled on wasm. Switched that to std::time::Duration as well, so tokio/time is now actually dropped from the wasm build.

Verified by reproducing the wasm-unknown CI job locally (cargo hack build --features ws --target wasm32-unknown-unknown with the same excludes): builds clean. tokio/time is no longer in the alloy-provider ws feature graph on wasm.

For reference, the test ... stable|nightly failures on this PR are pre-existing on main, unrelated to this change.

alloy-provider with the `ws` feature pulled `tokio` with the `time` feature on
wasm32-unknown-unknown, which panics at runtime when a tokio Runtime is built
there, crashing wasm apps that use alloy-provider/ws (alloy-rs#4023).

Two paths pulled `tokio/time` into the wasm build:
- tokio-stream's default features enable `time`; disable them at the workspace
  level (alloy-pubsub only uses tokio-stream's `sync`). This is the path in the
  issue's cargo tree.
- alloy-pubsub's `handle.rs` imported `tokio::time::Duration`; switch to
  `std::time::Duration` (same type; the `tokio::time` path needs the `time`
  feature, `Duration` does not).

alloy-pubsub already uses `wasmtimer::tokio::sleep` on wasm and `tokio::time::sleep`
off-wasm (where `tokio/time` is provided by alloy-transport), so this only removes
the feature from the wasm build.

Closes alloy-rs#4023.
@0xMars42 0xMars42 force-pushed the fix/tokio-stream-no-default branch from 1cc45cd to b5bfbc4 Compare June 11, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed

Development

Successfully merging this pull request may close these issues.

[Bug] Can't use alloy-provider/ws on wasm because of transitive dependency tokio-stream on alloy-pubsub

2 participants