Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap the maximum value passed to setTimeout #2188

Merged
merged 2 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed

- Fixed a `TimeoutOverflowWarning` caused by calling `setTimeout` with a value that is too large. ([#2188](https://github.com/paritytech/smoldot/pull/2188))

## 0.6.10 - 2022-03-29

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions bin/wasm-node/javascript/src/worker/bindings-smoldot-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ export default function (config: Config): compat.WasmModuleImports {
start_timer: (id: number, ms: number) => {
const instance = config.instance!;

// In both NodeJS and browsers, if `setTimeout` is called with a value larger than
// 2147483647, the delay is for some reason instead set to 1.
// As mentioned in the documentation of `start_timer`, it is acceptable to end the
// timer before the given number of milliseconds has passed.
if (ms > 2147483647)
ms = 2147483647;

// In browsers, `setTimeout` works as expected when `ms` equals 0. However, NodeJS
// requires a minimum of 1 millisecond (if `0` is passed, it is automatically replaced
// with `1`) and wants you to use `setImmediate` instead.
Expand Down
4 changes: 4 additions & 0 deletions bin/wasm-node/rust/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ extern "C" {
/// After at least `milliseconds` milliseconds have passed, must call [`timer_finished`] with
/// the `id` passed as parameter.
///
/// It is not a logic error to call [`timer_finished`] *before* `milliseconds` milliseconds
/// have passed, and this will likely cause smoldot to restart a new timer for the remainder
/// of the duration.
///
/// When [`timer_finished`] is called, the value of [`monotonic_clock_ms`] must have increased
/// by at least the given number of `milliseconds`.
///
Expand Down