Skip to content

Commit acae146

Browse files
authored
Merge pull request #6274 from cloudflare/jasnell/als-gc
2 parents 75c098c + 821c806 commit acae146

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

src/workerd/api/node/tests/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,9 @@ wd_test(
722722
args = ["--experimental"],
723723
data = ["buffer-effective-size-concat-test.js"],
724724
)
725+
726+
wd_test(
727+
src = "als-gc-test.wd-test",
728+
args = ["--experimental"],
729+
data = ["als-gc-test.js"],
730+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { AsyncLocalStorage } from 'node:async_hooks';
2+
3+
const store = new AsyncLocalStorage();
4+
5+
export const test = {
6+
test() {
7+
const outerValue = crypto.randomUUID();
8+
({ [outerValue]: `value doesn't matter here` });
9+
store.run(outerValue, () => {
10+
for (let i = 0; i < 1_000; i++) {
11+
const storeValue = store.getStore();
12+
if (!storeValue) {
13+
throw new Error(`Failed on attempt ${i}.`);
14+
}
15+
for (let j = 0; j < 1_000; j++) {
16+
(() => Math.random())();
17+
}
18+
}
19+
});
20+
},
21+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Workerd = import "/workerd/workerd.capnp";
2+
3+
const unitTests :Workerd.Config = (
4+
services = [
5+
( name = "als-gc-test",
6+
worker = (
7+
modules = [
8+
(name = "worker", esModule = embed "als-gc-test.js")
9+
],
10+
compatibilityFlags = ["nodejs_compat", "nodejs_compat_v2"]
11+
)
12+
),
13+
],
14+
);

src/workerd/jsg/async-context.c++

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ v8::Local<v8::Object> AsyncContextFrame::getJSWrapper(Lock& js) {
187187
}
188188

189189
void AsyncContextFrame::jsgVisitForGc(GcVisitor& visitor) {
190-
for (auto& entry: storage) {
191-
visitor.visit(entry.value);
192-
}
190+
// tracing will make the members weak and will allow
191+
// them to be gc'd, which is not what we want.
193192
}
194193
} // namespace workerd::jsg

0 commit comments

Comments
 (0)