Skip to content

Commit 23b757b

Browse files
committed
async_hooks: drop leftover legacy ALS paths
Remove the AsyncContextFrame.enabled checks and the async_local_storage_context_symbol that only served the async_hooks based implementation, and stop spawning test-timers-async-store-leak with --no-async-context-frame.
1 parent 44ac0b3 commit 23b757b

4 files changed

Lines changed: 7 additions & 60 deletions

File tree

lib/internal/async_hooks.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const before_symbol = Symbol('before');
105105
const after_symbol = Symbol('after');
106106
const destroy_symbol = Symbol('destroy');
107107
const promise_resolve_symbol = Symbol('promiseResolve');
108-
const async_local_storage_context_symbol = Symbol('kAsyncLocalStorageContext');
109108
const emitBeforeNative = emitHookFactory(before_symbol, 'emitBeforeNative');
110109
const emitAfterNative = emitHookFactory(after_symbol, 'emitAfterNative');
111110
const emitDestroyNative = emitHookFactory(destroy_symbol, 'emitDestroyNative');
@@ -585,7 +584,7 @@ module.exports = {
585584
symbols: {
586585
async_id_symbol, trigger_async_id_symbol,
587586
init_symbol, before_symbol, after_symbol, destroy_symbol,
588-
promise_resolve_symbol, async_local_storage_context_symbol,
587+
promise_resolve_symbol,
589588
owner_symbol,
590589
},
591590
constants: {

lib/internal/timers.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ const {
100100
emitBefore,
101101
emitAfter,
102102
emitDestroy,
103-
symbols: {
104-
async_local_storage_context_symbol,
105-
},
106103
} = require('internal/async_hooks');
107104

108105
// Symbols for storing async id state.
@@ -132,12 +129,8 @@ const AsyncContextFrame = require('internal/async_context_frame');
132129
const async_context_frame = Symbol('kAsyncContextFrame');
133130

134131
function removeStoresFromResource(resource) {
135-
if (AsyncContextFrame.enabled) {
136-
if (resource[async_context_frame] !== undefined) {
137-
resource[async_context_frame] = undefined;
138-
}
139-
} else if (resource[async_local_storage_context_symbol] !== undefined) {
140-
resource[async_local_storage_context_symbol] = undefined;
132+
if (resource[async_context_frame] !== undefined) {
133+
resource[async_context_frame] = undefined;
141134
}
142135
}
143136

test/parallel/test-stream-finished-async-local-storage.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// Flags: --expose-internals
21
'use strict';
32

43
const common = require('../common');
54
const { Readable, finished } = require('stream');
65
const { AsyncLocalStorage } = require('async_hooks');
76
const assert = require('assert');
8-
const AsyncContextFrame = require('internal/async_context_frame');
9-
const { enabledHooksExist } = require('internal/async_hooks');
107

118
// This test verifies that ALS context is preserved when using stream.finished()
129

@@ -15,7 +12,6 @@ const readable = new Readable();
1512

1613
als.run('test-context-1', common.mustCall(() => {
1714
finished(readable, common.mustCall(() => {
18-
assert.strictEqual(!!AsyncContextFrame.current() || enabledHooksExist(), true);
1915
assert.strictEqual(als.getStore(), 'test-context-1');
2016
}));
2117
}));

test/parallel/test-timers-async-store-leak.js

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,20 @@
22
'use strict';
33

44
const common = require('../common');
5-
const { spawnSyncAndAssert } = require('../common/child_process');
65
const { AsyncLocalStorage } = require('async_hooks');
76
const assert = require('assert');
8-
9-
if (process.argv[2] !== 'child') {
10-
// Test with async-context-frame disabled (legacy ALS mode)
11-
spawnSyncAndAssert(process.execPath, [
12-
'--expose-internals',
13-
'--expose-gc',
14-
'--no-async-context-frame',
15-
__filename,
16-
'child',
17-
], {});
18-
19-
// Test with async-context-frame enabled (default)
20-
spawnSyncAndAssert(process.execPath, [
21-
'--expose-internals',
22-
'--expose-gc',
23-
__filename,
24-
'child',
25-
], {});
26-
}
27-
28-
const AsyncContextFrame = require('internal/async_context_frame');
297
const {
308
async_context_frame,
319
} = require('internal/timers');
32-
const {
33-
symbols: {
34-
async_local_storage_context_symbol,
35-
},
36-
} = require('internal/async_hooks');
37-
38-
// When async-context-frame is enabled, stores are stored in the async context
39-
// frame, not directly on the resource. The resource holds a reference to the
40-
// frame via async_context_frame.
41-
const isACFEnabled = AsyncContextFrame.enabled;
42-
43-
function getStore(resource, als) {
44-
if (isACFEnabled) {
45-
return resource[async_context_frame]?.get(als);
46-
}
47-
return resource[async_local_storage_context_symbol]?.[als.kResourceStore];
48-
}
4910

11+
// Stores live in the async context frame, not directly on the resource. The
12+
// resource holds a reference to the frame via async_context_frame.
5013
function assertStore(resource, als, store) {
51-
assert.strictEqual(getStore(resource, als), store);
14+
assert.strictEqual(resource[async_context_frame]?.get(als), store);
5215
}
5316

5417
function assertNoStore(resource) {
55-
if (isACFEnabled) {
56-
assert.strictEqual(resource[async_context_frame], undefined);
57-
} else {
58-
assert.strictEqual(resource[async_local_storage_context_symbol], undefined);
59-
}
18+
assert.strictEqual(resource[async_context_frame], undefined);
6019
}
6120

6221
// Test that setTimeout does not retain a reference to the async store after

0 commit comments

Comments
 (0)