-
Notifications
You must be signed in to change notification settings - Fork 646
Return an error when scheduling a reducer with a long delay #77
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prior to this commit, it was possible for a module to crash SpacetimeDB by scheduling a reducer with a delay longer than ~2yrs. This was due to our use of `tokio_utils::time::DelayQueue` to handle scheduling. `DelayQueue`'s internal data structure imposes a limit of 64^6 ms on delays, a little more than two years. Attempting to insert with a delay longer than that panics. With this commit, we avoid the panic by checking ourselves that the requested delay is not longer than 64^6 ms. This requires bubbling a `ScheduleError` up from `Scheduler::schedule` to `WasmInstanceEnv::schedule`, where it is converted into a `RuntimeError` which crashes the module. `Scheduler::schedule` could also fail because its transaction to compute a new id was fallible. This seems unlikely to ever fail, and if it does, we have bigger problems, so `unwrap`ping might still be reasonable for that case, but this commit converts it into a handle-able `Err`or anyway, as there's essentially no cost in complexity to doing so.
jdetter
approved these changes
Jul 13, 2023
Collaborator
jdetter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, SpacetimeDB no longer crashes. We don't really get a meaningful error in the case of using spacetime call from the command line:
Error: Response text: The Wasm instance encountered a fatal error.
Caused by:
HTTP status server error (530 <unknown status code>) for url (http://localhost:3000/database/call/93dda09db9a56d8fa6c024d843e805d8/test)
And also it appears that the module logs are empty. I think this error is going to be extremely uncommon so this is fine for now.
cloutiertyler
pushed a commit
that referenced
this pull request
Aug 1, 2023
Prior to this commit, it was possible for a module to crash SpacetimeDB by scheduling a reducer with a delay longer than ~2yrs. This was due to our use of `tokio_utils::time::DelayQueue` to handle scheduling. `DelayQueue`'s internal data structure imposes a limit of 64^6 ms on delays, a little more than two years. Attempting to insert with a delay longer than that panics. With this commit, we avoid the panic by checking ourselves that the requested delay is not longer than 64^6 ms. This requires bubbling a `ScheduleError` up from `Scheduler::schedule` to `WasmInstanceEnv::schedule`, where it is converted into a `RuntimeError` which crashes the module. `Scheduler::schedule` could also fail because its transaction to compute a new id was fallible. This seems unlikely to ever fail, and if it does, we have bigger problems, so `unwrap`ping might still be reasonable for that case, but this commit converts it into a handle-able `Err`or anyway, as there's essentially no cost in complexity to doing so.
cloutiertyler
pushed a commit
that referenced
this pull request
Aug 1, 2023
Prior to this commit, it was possible for a module to crash SpacetimeDB by scheduling a reducer with a delay longer than ~2yrs. This was due to our use of `tokio_utils::time::DelayQueue` to handle scheduling. `DelayQueue`'s internal data structure imposes a limit of 64^6 ms on delays, a little more than two years. Attempting to insert with a delay longer than that panics. With this commit, we avoid the panic by checking ourselves that the requested delay is not longer than 64^6 ms. This requires bubbling a `ScheduleError` up from `Scheduler::schedule` to `WasmInstanceEnv::schedule`, where it is converted into a `RuntimeError` which crashes the module. `Scheduler::schedule` could also fail because its transaction to compute a new id was fallible. This seems unlikely to ever fail, and if it does, we have bigger problems, so `unwrap`ping might still be reasonable for that case, but this commit converts it into a handle-able `Err`or anyway, as there's essentially no cost in complexity to doing so.
bfops
added a commit
that referenced
this pull request
Jul 16, 2025
* Lint script * modernize: pnpm & prettier (#51) * Push * Push * Run prettier * Prettier stuff * modernize: Remove Husky & pre-commit (#53) * modernize: tsup (#54) * Push * jest * modernize: jest to vitest (#55) * modernize: pnpm workspace (#56) * Monorepo * Readme * Move tsconfig * Fix test * modernize: CRA -> Vite apps (#57) * Quickstart * test app too * Run pnpm * Remove eslint files * Format * modernize: ES2017 classes (#58) * modernize: in-house EventEmitter (#64) * Push * Undo min change * modernize: undici for WebSocket in Node (#59) * Use undici, remove other unneeded dependencies * pnpm install * Bundle everything * Move everything to devDependency * headers object * Bump version to 0.11.0 * Push * Hmm not working still * Add undici to peerDependencies * Measure size * Push * Fix formatting * Working on node!! --------- Co-authored-by: Zeke Foppa <github.com/bfops> Co-authored-by: Zeke Foppa <[email protected]> * modernize: Single output (#68) * modernize: quickstart, move server into client (#69) * Push * Run pnpm install * modernize: Engines field (#70) * modernize: Continuous Releases (#71) * Add pkg.pr.new * Fix directory * modernize: Changesets;provenance (#72) * Push * Push * pnpm install * Any update * modernize: Split lint and test GH actions (#73) * Push * Forgot to rename * We only care about Lint at commit level * modernize: pkg.pr.new compact mode (#75) * modernize: tweak prettier configuration (#74) * docs: Undici as peerDependency * modernize: webpackIgnore undici (#77) * Push * Webpackignore * modernize: Conditional browser build (#79) * Push * Remove webpackIgnore * fix: Remove obsolete comment * modernize: isolatedDeclarations;de-cyclic imports (#81) * Push * Fix test --------- Co-authored-by: Zeke Foppa <[email protected]>
bfops
pushed a commit
that referenced
this pull request
Jul 17, 2025
bfops
pushed a commit
that referenced
this pull request
Jul 17, 2025
bfops
added a commit
that referenced
this pull request
Aug 7, 2025
* Lint script * modernize: pnpm & prettier (#51) * Push * Push * Run prettier * Prettier stuff * modernize: Remove Husky & pre-commit (#53) * modernize: tsup (#54) * Push * jest * modernize: jest to vitest (#55) * modernize: pnpm workspace (#56) * Monorepo * Readme * Move tsconfig * Fix test * modernize: CRA -> Vite apps (#57) * Quickstart * test app too * Run pnpm * Remove eslint files * Format * modernize: ES2017 classes (#58) * modernize: in-house EventEmitter (#64) * Push * Undo min change * modernize: undici for WebSocket in Node (#59) * Use undici, remove other unneeded dependencies * pnpm install * Bundle everything * Move everything to devDependency * headers object * Bump version to 0.11.0 * Push * Hmm not working still * Add undici to peerDependencies * Measure size * Push * Fix formatting * Working on node!! --------- Co-authored-by: Zeke Foppa <github.com/bfops> Co-authored-by: Zeke Foppa <[email protected]> * modernize: Single output (#68) * modernize: quickstart, move server into client (#69) * Push * Run pnpm install * modernize: Engines field (#70) * modernize: Continuous Releases (#71) * Add pkg.pr.new * Fix directory * modernize: Changesets;provenance (#72) * Push * Push * pnpm install * Any update * modernize: Split lint and test GH actions (#73) * Push * Forgot to rename * We only care about Lint at commit level * modernize: pkg.pr.new compact mode (#75) * modernize: tweak prettier configuration (#74) * docs: Undici as peerDependency * modernize: webpackIgnore undici (#77) * Push * Webpackignore * modernize: Conditional browser build (#79) * Push * Remove webpackIgnore * fix: Remove obsolete comment * modernize: isolatedDeclarations;de-cyclic imports (#81) * Push * Fix test --------- Co-authored-by: Zeke Foppa <[email protected]>
bfops
pushed a commit
that referenced
this pull request
Aug 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
Prior to this commit, it was possible for a module to crash SpacetimeDB by scheduling a reducer with a delay longer than ~2yrs. This was due to our use of
tokio_utils::time::DelayQueueto handle scheduling.DelayQueue's internal data structure imposes a limit of 64^6 ms on delays, a little more than two years.Attempting to insert with a delay longer than that panics.
With this commit, we avoid the panic by checking ourselves that the requested delay is not longer than 64^6 ms.
This requires bubbling a
ScheduleErrorup fromScheduler::scheduletoWasmInstanceEnv::schedule, where it is converted into aRuntimeErrorwhich crashes the module.Scheduler::schedulecould also fail because its transaction to compute a new id was fallible. This seems unlikely to ever fail, and if it does, we have bigger problems, sounwrapping might still be reasonable for that case, but this commit converts it into a handle-ableError anyway, as there's essentially no cost in complexity to doing so.API
If the API is breaking, please state below what will break