Skip to content

Validate sleep duration is non-negative. #537

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

Merged
merged 2 commits into from
May 13, 2025
Merged

Validate sleep duration is non-negative. #537

merged 2 commits into from
May 13, 2025

Conversation

nikrooz
Copy link
Contributor

@nikrooz nikrooz commented May 13, 2025

Before:

At the moment a negative sleep duration causes the service to crash with this error

[restate][2025-05-13T08:31:17.172Z][greeter/greet][inv_18mP0bGrYLaj5Z610aSA2q60Kh2chnBoSG] DEBUG: Executing 'Timer with duration 18446744073709551.615s'
panicked at /home/slinkydeveloper/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/restate-sdk-shared-core-0.3.0/src/vm/mod.rs:678:22:
millis since Unix epoch should fit in u64: TryFromIntError(())

Stack:

Error
    at imports.wbg.__wbg_new_8a6f238a6ece86ea (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:1383:17)
    at wasm://wasm/00310276:wasm-function[1479]:0xa756e
    at wasm://wasm/00310276:wasm-function[433]:0x5c4a3
    at wasm://wasm/00310276:wasm-function[1030]:0x91d71
    at wasm://wasm/00310276:wasm-function[586]:0x67280
    at wasm://wasm/00310276:wasm-function[1032]:0x94bc5
    at WasmVM.sys_sleep (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:831:22)
    at <anonymous> (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:443:18)
    at ContextImpl.processCompletableEntry (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:554:16)
    at ContextImpl.sleep (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:442:17)


[restate][2025-05-13T08:31:17.174Z][greeter/greet][inv_18mP0bGrYLaj5Z610aSA2q60Kh2chnBoSG] WARN: Error when processing a Restate context operation.
 RuntimeError: unreachable
    at wasm://wasm/00310276:wasm-function[433]:0x5c4c7
    at wasm://wasm/00310276:wasm-function[1030]:0x91d71
    at wasm://wasm/00310276:wasm-function[586]:0x67280
    at wasm://wasm/00310276:wasm-function[1032]:0x94bc5
    at WasmVM.sys_sleep (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:831:22)
    at <anonymous> (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:443:18)
    at ContextImpl.processCompletableEntry (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:554:16)
    at ContextImpl.sleep (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:442:17)
    at Object.greet (/Users/nik/Developer/sdk-typescript/packages/restate-sdk-examples/src/greeter.ts:18:17)
    at Object.handlerCopy (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/types/rpc.ts:390:22)
[restate][2025-05-13T08:31:17.176Z][greeter/greet][inv_18mP0bGrYLaj5Z610aSA2q60Kh2chnBoSG] WARN: Invocation completed with an error.
 Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at imports.wbg.__wbindgen_throw (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:1600:11)
    at wasm://wasm/00310276:wasm-function[1435]:0xa6778
    at wasm://wasm/00310276:wasm-function[1437]:0xa6794
    at wasm://wasm/00310276:wasm-function[719]:0x6ece3
    at wasm://wasm/00310276:wasm-function[458]:0x5e1d5
    at WasmVM.notify_error (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:693:10)
    at ContextImpl.handleInvocationEndError (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:573:17)
    at ContextImpl.processCompletableEntry (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:556:12)
    at ContextImpl.sleep (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/context_impl.ts:442:17)
    at Object.greet (/Users/nik/Developer/sdk-typescript/packages/restate-sdk-examples/src/greeter.ts:18:17)
file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:1600
    throw new Error(getStringFromWasm0(arg0, arg1));
          ^

Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at imports.wbg.__wbindgen_throw (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:1600:11)
    at wasm://wasm/00310276:wasm-function[1435]:0xa6778
    at wasm://wasm/00310276:wasm-function[1437]:0xa6794
    at wasm://wasm/00310276:wasm-function[719]:0x6ece3
    at wasm://wasm/00310276:wasm-function[458]:0x5e1d5
    at WasmVM.notify_error (file:///Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js:693:10)
    at <anonymous> (/Users/nik/Developer/sdk-typescript/packages/restate-sdk/src/endpoint/handlers/generic.ts:385:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

After:

Screenshot 2025-05-13 at 12 13 17

One downside of this approach is that we will not have a SLEEP COMMAND entry in the journal. Since the duration of sleep is recorded as part of an immutable SLEEP entry, I am not sure what's the best way to commit the entry while keeping the error recoverable (ie. changing the duration).

@nikrooz nikrooz changed the title Validate sleep duration in non-negative Validate sleep duration is non-negative. May 13, 2025
Copy link

github-actions bot commented May 13, 2025

Test Results

  7 files  ±0    7 suites  ±0   3m 40s ⏱️ +11s
 54 tests ±0   53 ✅ ±0  1 💤 ±0  0 ❌ ±0 
223 runs  ±0  220 ✅ ±0  3 💤 ±0  0 ❌ ±0 

Results for commit c81c452. ± Comparison against base commit 6b7bf97.

♻️ This comment has been updated with latest results.

nikrooz added 2 commits May 13, 2025 19:13
Signed-off-by: Nik Nasr <nik@restate.dev>
Signed-off-by: Nik Nasr <nik@restate.dev>
@nikrooz nikrooz merged commit c4f6bd9 into main May 13, 2025
3 checks passed
@nikrooz nikrooz deleted the NN_fix-sleep branch May 13, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants