Skip to content

Commit 486f5a5

Browse files
committed
refactor(example): move V8 suspend support to a dependent change
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 18b8e01 commit 486f5a5

9 files changed

Lines changed: 74 additions & 1105 deletions

File tree

‎examples/isolation-backend-v8/Cargo.lock‎

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/isolation-backend-v8/Cargo.toml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ rustix = { version = "1", features = ["process"] }
2121
tokio-rustls = "0.26"
2222
rustls = "0.23"
2323
rustls-pemfile = "2"
24-
hmac = "0.12"
2524
clap = { version = "4.5", features = ["derive", "env"] }
2625
prost = "0.14"
2726
prost-types = "0.14"
@@ -36,10 +35,6 @@ uuid = { version = "1", features = ["v4"] }
3635

3736
v8 = "152.2.0"
3837

39-
[dev-dependencies]
40-
tempfile = "3"
41-
rcgen = { version = "0.13", default-features = false, features = ["crypto", "pem", "aws_lc_rs"] }
42-
4338
[build-dependencies]
4439
protoc-bin-vendored = "3"
4540
tonic-prost-build = "0.14"

‎examples/isolation-backend-v8/README.md‎

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ openshell sandbox create --name js-demo \
6161
--keep --no-tty --no-auto-providers -- /work/guest.js
6262
```
6363

64-
The bundled script prints a greeting, attempts a request, catches the
65-
network-disabled error, and counts once per second for about 12 seconds.
66-
Egress is disabled by the runtime's lack of network bindings; this example
67-
does not relay requests to the supervisor for policy evaluation. No policy
68-
file is needed.
64+
The bundled script prints a greeting, attempts a request, and catches the
65+
network-disabled error. Egress is disabled by the runtime's lack of network
66+
bindings; this example does not relay requests to the supervisor for policy
67+
evaluation. No policy file is needed.
6968

7069
The create command prints the script's output and returns its exit code. The
7170
sandbox becomes `Completed` on exit code 0 or `Error` on a nonzero exit code.
@@ -76,54 +75,6 @@ print an error and return exit code 1.
7675
Add `--detach` to run without attaching; detached creation does not stream guest
7776
output. Use `openshell sandbox connect js-demo` to attach afterward.
7877

79-
## Suspend and resume
80-
81-
Suspension freezes the V8 isolate in place and the `js-sbx serve` process keeps
82-
it in memory; resume continues the same isolate in a new runtime generation.
83-
The default `guest.js` counts for about 12 seconds after its network check:
84-
85-
```shell
86-
./start.sh
87-
```
88-
89-
In another terminal, create the sandbox, then suspend and resume it while it
90-
counts:
91-
92-
```shell
93-
openshell sandbox create --name js-demo \
94-
--keep --no-tty --no-auto-providers --detach -- /work/guest.js
95-
openshell sandbox suspend js-demo
96-
openshell sandbox resume js-demo
97-
```
98-
99-
To discard the retained state and start the script from the beginning:
100-
101-
```shell
102-
openshell sandbox stop js-demo
103-
openshell sandbox start js-demo
104-
```
105-
106-
`backend.log` shows the count continue from its value at suspension, and the
107-
elapsed time includes the gap. The 15-second deadline counts only running time.
108-
109-
The driver sends `SIGUSR1` to the supervisor, which calls `SuspendBoundary`.
110-
The backend retains the frozen isolate and privately persists its handle in
111-
`restore-reference` before acknowledging suspension. The supervisor exits;
112-
it does not write or read a reference file. On resume the driver provisions
113-
the backend using `launch.json`, while the supervisor attaches through its
114-
ordinary boundary-opening path. The shared `boundary.json` contains no
115-
retention fields. The reference authenticates the sandbox with a key in
116-
`retention.key`, so a restarted `js-sbx serve` can tell lost state from a forged
117-
or superseded reference. If you restart `js-sbx serve` while the sandbox is suspended, resume
118-
fails and the sandbox stays `Suspended`; `openshell sandbox start js-demo`
119-
then runs the script from the beginning.
120-
`openshell sandbox start`, `stop`, and `delete` discard the retained state.
121-
122-
Restoration borrows the retained guest until the driver observes supervisor
123-
readiness and consumes `restore-reference`. If startup fails or times out,
124-
the driver stops the supervisor and waits for the backend to refreeze the guest
125-
before reporting failure. The same reference remains available for a retry.
126-
12778
## Inspect and stop
12879

12980
```shell
@@ -143,5 +94,5 @@ limits do not bound all native V8 resources. The V8 isolate confines JavaScript;
14394
the host process does not run in a Linux namespace or container.
14495

14596
The example has no HTTP relay or guest network implementation. `fetch` is only
146-
a synchronous denial stub. Exec, PTY, providers, and supervisor recovery are
147-
unsupported. Retained state lives only in the `js-sbx serve` process memory.
97+
a synchronous denial stub. Exec, PTY, providers, suspend/resume, and supervisor
98+
recovery are unsupported.

‎examples/isolation-backend-v8/guest.js‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,3 @@ try {
99
if (error.message !== "Network access is disabled") throw error;
1010
console.log(error.message);
1111
}
12-
13-
// Counts once per second of running time. The guest has no timers, so it
14-
// busy-waits. Suspend partway through; after resume the count continues from
15-
// the value held in the isolate's memory.
16-
const started = Date.now();
17-
let count = 0;
18-
let next = Date.now() + 1000;
19-
while (count < 12) {
20-
if (Date.now() >= next) {
21-
count += 1;
22-
next = Date.now() + 1000;
23-
console.log(`count ${count} (${Math.round((Date.now() - started) / 1000)}s since start)`);
24-
}
25-
}
26-
console.log("done");

0 commit comments

Comments
 (0)