Skip to content

Commit 0d2a3ae

Browse files
committed
v8, syscalls: deal with JsInstanceEnv being potentially unset
1 parent d29c9bd commit 0d2a3ae

File tree

3 files changed

+129
-72
lines changed

3 files changed

+129
-72
lines changed

crates/core/src/host/v8/budget.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ pub(super) type InterruptCallback = extern "C" fn(&mut Isolate, *mut c_void);
4949
/// every [`EPOCH_TICKS_PER_SECOND`] ticks (~every 1 second)
5050
/// to log that the reducer is still running.
5151
pub(super) extern "C" fn cb_log_long_running(isolate: &mut Isolate, _: *mut c_void) {
52-
let env = env_on_isolate(isolate);
52+
let Some(env) = env_on_isolate(isolate) else {
53+
// All we can do is log something.
54+
tracing::error!("`JsInstanceEnv` not set");
55+
return;
56+
};
5357
let database = env.instance_env.replica_ctx.database_identity;
5458
let reducer = env.reducer_name();
5559
let dur = env.reducer_start().elapsed();

crates/core/src/host/v8/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ impl JsModule {
134134
}
135135
}
136136

137-
/// Access the `JsInstanceEnv` bound to an [`Isolate`].
138-
///
139-
/// This assumes that the slot has been set in the isolate already.
140-
fn env_on_isolate(isolate: &mut Isolate) -> &mut JsInstanceEnv {
141-
isolate.get_slot_mut().expect("there should be a `JsInstanceEnv`")
137+
/// Returns the `JsInstanceEnv` bound to an [`Isolate`], fallibly.
138+
fn env_on_isolate(isolate: &mut Isolate) -> Option<&mut JsInstanceEnv> {
139+
isolate.get_slot_mut()
140+
}
141+
142+
/// Returns the `JsInstanceEnv` bound to an [`Isolate`], or panic if not set.
143+
fn env_on_isolate_unwrap(isolate: &mut Isolate) -> &mut JsInstanceEnv {
144+
env_on_isolate(isolate).expect("there should be a `JsInstanceEnv`")
142145
}
143146

144147
/// The environment of a [`JsInstance`].
@@ -574,7 +577,7 @@ fn call_reducer<'scope>(
574577

575578
let (res, _) = instance_common.call_reducer_with_tx(replica_ctx, tx, params, log_traceback, |tx, op, budget| {
576579
// TODO(v8): Start the budget timeout and long-running logger.
577-
let env = env_on_isolate(scope);
580+
let env = env_on_isolate_unwrap(scope);
578581
let mut tx_slot = env.instance_env.tx.clone();
579582

580583
// Start the timer.
@@ -607,7 +610,7 @@ fn call_reducer<'scope>(
607610
});
608611

609612
// Finish timings.
610-
let timings = env_on_isolate(scope).finish_reducer();
613+
let timings = env_on_isolate_unwrap(scope).finish_reducer();
611614

612615
// Derive energy stats.
613616
let energy = energy_from_elapsed(budget, timings.total_duration);

0 commit comments

Comments
 (0)