fix(runtime): make timer IDs 1-based to avoid sentinel collision#5379
fix(runtime): make timer IDs 1-based to avoid sentinel collision#5379iammdzaidalam wants to merge 3 commits into
Conversation
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5379 +/- ##
===========================================
+ Coverage 47.24% 60.04% +12.79%
===========================================
Files 476 566 +90
Lines 46892 63037 +16145
===========================================
+ Hits 22154 37850 +15696
- Misses 24738 25187 +449 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c5c9a90 to
ea51866
Compare
|
hello @hansl @jedel1043, updated the pr.
also had to fix a windows WPT path issue, add If needed i can split the last part. |
hansl
left a comment
There was a problem hiding this comment.
I'm not convinced we need clear_jobs. We shouldn't need to clear jobs and should fail if jobs are not completed by the end of the run. Let me think a bit more about it.
|
hi @hansl. i went with this because without for now i used |
|
@iammdzaidalam Hey Zaid. Sorry for the late reply I was out on a trip last weekend, and thinking about how to approach this. What you actually want to do is not cancel jobs (there are jobs in there that aren't timers/intervals). You want to clear timers themselves and let the engine exit gracefully. Am I right? In that case, what you could do is add a What do you think? |
|
Hey @hansl, hope the trip was good 😊. tried a repro with a Also confirmed the hang directly. Also i am keeping the 10 second deadline in the harness so we notice if something else holds the loop open later. seems like the right direction, thanks! |
Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
…sues Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
…plicate WPT path Signed-off-by: iammdzaidalam <161572905+iammdzaidalam@users.noreply.github.com>
2881319 to
6389f83
Compare
hansl
left a comment
There was a problem hiding this comment.
Nothing major, but I'm curious why the rustls dependency was added.
| fn encoding( | ||
| #[base_dir = "${WPT_ROOT}"] | ||
| #[files("encoding/api-*.any.js")] | ||
| #[files("encoding/textencoder-constructor-non-utf.any.js")] |
There was a problem hiding this comment.
Oops, accidental removal while fixing path handling. Restoring it.
| // in clippy. | ||
| #[allow(unused)] | ||
| fn execute_test_file(path: &Path) { | ||
| rustls::crypto::ring::default_provider().install_default().ok(); |
There was a problem hiding this comment.
The test runner needs it, not any specific test. Workspace reqwest is pinned with rustls-no-provider so reqwest::blocking::Client panics with No provider set without a CryptoProvider installed. create_context() builds a WptFetcher (and a reqwest Client) for every test so the suite won't run without it.
I removed the line locally to verify, encoding and timers both panic the same way. Checked main too and cargo test encoding fails identically there, so this is a latent harness issue ig, not something this PR introduced.
Same install already exists in cli/src/main.rs and examples/src/bin/module_fetch_async.rs. Happy to split it out or add a comment, whichever works.
| } | ||
|
|
||
| /// Clears all queued jobs from the job executor. | ||
| #[inline] |
There was a problem hiding this comment.
If it's not needed, I'd rather like to leave it out of the PR.
There was a problem hiding this comment.
yep not needed anymore after the switch to interval::clear_all. will remove in next push.
Closes #5378
Problem
IntervalInnerState::next_id()returns the internal counter before incrementing it. Since the counter starts at0viaDefault, the first valid timer gets handle0:At the same time, both
set_timeoutandset_intervalreturnOk(0)when no callback is provided. That makes the first real timer and the "nothing was scheduled" sentinel indistinguishable. It also violates WHATWG HTML timer semantics, which require positive timer handles, and breaks common JavaScript code that treats a returned timer ID as truthy.Fix
Update
next_id()to increment the counter before returning it, so valid timer IDs become 1-based again. This preserves0for the no-callback sentinel and restores the pre-#5289 behavior.Tests
timer_ids_are_positive_and_uniqueasserts that timer IDs returned bysetTimeoutandsetIntervalare greater than0and unique.no_callback_returns_zero_sentinelasserts thatsetTimeout()with no callback still returns0and does not collide with a valid timer ID.Verification
cargo test -p boa_runtimecargo run -p boa_cli -- -e "console.log(setTimeout(() => {}, 10)); console.log(setTimeout(() => {}, 10)); console.log(setTimeout())"Before the fix, the first valid timer returned
0. After the fix, the output is1,2,0.