rt: do not track time-based metrics on wasm32-unknown-unknown#7322
rt: do not track time-based metrics on wasm32-unknown-unknown#7322Darksonn merged 7 commits intotokio-rs:tokio-1.45.xfrom
Conversation
|
|
||
| #[cfg(target_family = "wasm")] | ||
| pub(crate) fn new_for_wasm() -> MetricsBatch { | ||
| Self::new_unstable_for_wasm() |
There was a problem hiding this comment.
what do you think instead about a function like:
fn now() -> Option<Instant> {
if cfg!(target_family = "wasm") { None } else { Instant::now() }
}
Then use that everywhere that its needed? Since WASM can compile the now function, it just can't call it, I think this should more or less take care of it
There was a problem hiding this comment.
Good idea, I'm on board with that
| if let Some(processing_scheduled_tasks_started_at) = | ||
| self.processing_scheduled_tasks_started_at | ||
| { | ||
| let busy_duration = processing_scheduled_tasks_started_at.elapsed(); |
There was a problem hiding this comment.
I like the impact of making this optional since it ensures we can't call elapsed() unless we actually got an instant.
| #[inline(always)] | ||
| fn new_unstable(worker_metrics: &WorkerMetrics, now: Instant) -> MetricsBatch { | ||
| fn new_unstable(worker_metrics: &WorkerMetrics, maybe_now: Option<Instant>) -> MetricsBatch { | ||
| let poll_timer = maybe_now.map_or(None, |now| { |
There was a problem hiding this comment.
ah right, I guess and_then due to the extra option?
| u64::try_from(dur.as_nanos()).unwrap_or(u64::MAX) | ||
| } | ||
|
|
||
| fn now() -> Option<Instant> { |
| if self.processing_scheduled_tasks_started_at.is_some() { | ||
| self.processing_scheduled_tasks_started_at = Some(Instant::now()); | ||
| } | ||
| } |
a6c8891 to
266709e
Compare
time is unsupported in WASM, fix involves removing Instant from metrics handling for cfg gated WASM target family as a stopgap solution
| u64::try_from(dur.as_nanos()).unwrap_or(u64::MAX) | ||
| } | ||
|
|
||
| /// `WASM` does not support time: <https://github.com/tokio-rs/tokio/issues/7319> |
There was a problem hiding this comment.
The major problem here is that WASM does support time ... sometimes. Perhaps we could change this logic to only apply when you enable the time feature of Tokio? I'm not sure if that would be breaking.
There was a problem hiding this comment.
That seems reasonable. In the longer term, we could add a builder option to opt in or out of these time based metrics.
There was a problem hiding this comment.
Thanks. Added this, let me know if we wanted to conditionally compile the fields as well, but it seems viable to leave them as None when time is not enabled (esp if it's a temporary fix).
017d1ad to
71b5702
Compare
rcoh
left a comment
There was a problem hiding this comment.
LGTM — This sounds like a good stopgap to unbreak people who are broken by the current release. Not sure what the right long term option is.
|
@jccampagne does this work for you? |
|
Hi, thanks for the reply; I am offline for a few days; will try later in the week. |
|
I just tested it - it works for me. |
|
Sorry, I still have a question about this. Does this mean that we still are making a breaking change in this scenario:
After all, I think but am not sure that this works today as long as you don't actually use |
|
This change is very narrow, it's only for metrics. These metrics could never have worked since they call Instant::now. The set of people broken by this change is:
These customers would previously have non zero values for these metrics but now they don't. However, these metrics were only stabilized in the last release. |
|
I don't mean broken just by this change since last release, but broken since the release before that - after all, that's the breakage this is trying to fix. |
|
oh yeah I see what you're saying. Unfortunately this change fully solves neither:
Ultimately the only thing that would actually work is:
I started a discussion to this effect here. |
| /// Gate time metrics as platforms like `WASM` do not typically support [`std::time`] | ||
| /// <https://github.com/tokio-rs/tokio/issues/7319> | ||
| fn now() -> Option<Instant> { | ||
| if cfg!(target_family = "wasm") && !cfg!(feature = "time") { |
There was a problem hiding this comment.
You should do an exact match: cfg!(all(target_arch = "wasm", target_os = "unknown", target_vendor = "unknown")). Instant::now should be available just fine on all other Wasm targets that have std.
It is not expected that any new broken targets like this will be added.
34a5d95 to
0a0ee85
Compare
Darksonn
left a comment
There was a problem hiding this comment.
Thank you. Now working on merging this to tokio-1.45.x for a patch release.
The time feature is not relevant here. WASM with time enabled should wokr on wasm32-unknown-unknown as long as you don't actually call tokio::time::sleep.
Bumps tokio from 1.45.0 to 1.45.1. Release notes Sourced from tokio's releases. Tokio v1.45.1 1.45.1 (May 24th, 2025) This fixes a regression on the wasm32-unknown-unknown target, where code that previously did not panic due to calls to Instant::now() started failing. This is due to the stabilization of the first time-based metric. Fixed Disable time-based metrics on wasm32-unknown-unknown (#7322) #7322: tokio-rs/tokio#7322 Commits 3768696 chore: prepare Tokio v1.45.1 (#7359) 421a7b0 rt: do not track time-based metrics on wasm32-unknown-unknown (#7322) b1bdb3c ci: update macros_type_mismatch for Rust 1.87.0 (#7339) See full diff in compare view Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase. Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: @dependabot rebase will rebase this PR @dependabot recreate will recreate this PR, overwriting any edits that have been made to it @dependabot merge will merge this PR after your CI passes on it @dependabot squash and merge will squash and merge this PR after your CI passes on it @dependabot cancel merge will cancel a previously requested merge and block automerging @dependabot reopen will reopen this PR if it is closed @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Fix for #7319
Time is generally unsupported in WASM. Fix involves removing Instant from metrics handling when WASM is the target family and tokio's time feature is not enabled.
NOTES:
Will iterate with a test to catch this in the future.