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

Return an error when scheduling a reducer with a long delay #77

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Jul 13, 2023

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::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 unwrapping might still be reasonable for that case, but this commit converts it into a handle-able Error anyway, as there's essentially no cost in complexity to doing so.

API

  • This is a breaking change to the module API
  • This is a breaking change to the ClientAPI

If the API is breaking, please state below what will break

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.
Copy link
Collaborator

@jdetter jdetter left a 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.

@gefjon gefjon merged commit 882d4cf into master Jul 13, 2023
4 checks passed
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.
@cloutiertyler cloutiertyler deleted the phoebe/handle-schedule-duration-too-long branch August 1, 2023 21:55
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