Return an error when scheduling a reducer with a long delay #77
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::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 fromScheduler::schedule
toWasmInstanceEnv::schedule
, where it is converted into aRuntimeError
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, sounwrap
ping might still be reasonable for that case, but this commit converts it into a handle-ableErr
or anyway, as there's essentially no cost in complexity to doing so.API
If the API is breaking, please state below what will break