Skip to content

Commit 1c19701

Browse files
authored
fix(sb_core): add an API for chaos testing (#411)
1 parent 2b1945c commit 1c19701

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

crates/sb_core/js/main_worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Object.defineProperty(globalThis, 'EdgeRuntime', {
1111
getRuntimeMetrics: () => /* async */ ops.op_runtime_metrics(),
1212
applySupabaseTag: (src, dest) => applySupabaseTag(src, dest),
1313
systemMemoryInfo: () => ops.op_system_memory_info(),
14+
raiseSegfault: () => ops.op_raise_segfault(),
1415
};
1516
},
1617
configurable: true,

crates/sb_core/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ fn op_set_raw(
343343
Ok(())
344344
}
345345

346+
#[op2(fast)]
347+
fn op_raise_segfault(_state: &mut OpState) {
348+
unsafe {
349+
let ptr: *const i32 = std::ptr::null();
350+
println!("{}", *ptr);
351+
}
352+
}
353+
346354
#[op2]
347355
#[serde]
348356
pub fn op_bootstrap_unstable_args(_state: &mut OpState) -> Vec<String> {
@@ -361,7 +369,8 @@ deno_core::extension!(
361369
op_schedule_mem_check,
362370
op_runtime_memory_usage,
363371
op_set_raw,
364-
op_bootstrap_unstable_args
372+
op_bootstrap_unstable_args,
373+
op_raise_segfault,
365374
],
366375
esm_entry_point = "ext:sb_core_main_js/js/bootstrap.js",
367376
esm = [

examples/main/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ Deno.serve(async (req: Request) => {
2525
);
2626
}
2727

28+
// if (pathname === '/_internal/segfault') {
29+
// EdgeRuntime.raiseSegfault();
30+
// return new Response(
31+
// JSON.stringify({ 'message': 'ok' }),
32+
// {
33+
// status: STATUS_CODE.OK,
34+
// headers,
35+
// },
36+
// );
37+
// }
38+
2839
if (pathname === '/_internal/metric') {
2940
const metric = await EdgeRuntime.getRuntimeMetrics();
3041
return Response.json(metric);

0 commit comments

Comments
 (0)