Skip to content

Commit 48157c4

Browse files
RaisinTentargos
authored andcommitted
Revert "async_hooks: merge resource_symbol with owner_symbol"
This reverts commit 7ca2f13. PR-URL: #40741 Fixes: #40693 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent b614b17 commit 48157c4

9 files changed

+21
-71
lines changed

lib/_http_agent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ function asyncResetHandle(socket) {
525525
const handle = socket._handle;
526526
if (handle && typeof handle.asyncReset === 'function') {
527527
// Assign the handle a new asyncId and run any destroy()/init() hooks.
528-
handle.asyncReset(new ReusedHandle(handle.getProviderType(), socket));
528+
handle.asyncReset(new ReusedHandle(handle.getProviderType(), handle));
529529
socket[async_id_symbol] = handle.getAsyncId();
530530
}
531531
}

lib/internal/async_hooks.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const active_hooks = {
8181

8282
const { registerDestroyHook } = async_wrap;
8383
const { enqueueMicrotask } = internalBinding('task_queue');
84-
const { owner_symbol } = internalBinding('symbols');
84+
const { resource_symbol, owner_symbol } = internalBinding('symbols');
8585

8686
// Each constant tracks how many callbacks there are for any given step of
8787
// async execution. These are tracked so if the user didn't include callbacks
@@ -176,13 +176,11 @@ function fatalError(e) {
176176

177177
function lookupPublicResource(resource) {
178178
if (typeof resource !== 'object' || resource === null) return resource;
179-
180-
const publicResource = resource[owner_symbol];
181-
182-
if (publicResource != null) {
179+
// TODO(addaleax): Merge this with owner_symbol and use it across all
180+
// AsyncWrap instances.
181+
const publicResource = resource[resource_symbol];
182+
if (publicResource !== undefined)
183183
return publicResource;
184-
}
185-
186184
return resource;
187185
}
188186

lib/internal/js_stream_socket.js

+5-45
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,15 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
2222
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
2323
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');
2424

25-
function isClosing() {
26-
let socket = this[owner_symbol];
25+
function isClosing() { return this[owner_symbol].isClosing(); }
2726

28-
if (socket.constructor.name === 'ReusedHandle') {
29-
socket = socket.handle;
30-
}
31-
32-
return socket.isClosing();
33-
}
34-
35-
function onreadstart() {
36-
let socket = this[owner_symbol];
37-
38-
if (socket.constructor.name === 'ReusedHandle') {
39-
socket = socket.handle;
40-
}
41-
42-
return socket.readStart();
43-
}
44-
45-
function onreadstop() {
46-
let socket = this[owner_symbol];
47-
48-
if (socket.constructor.name === 'ReusedHandle') {
49-
socket = socket.handle;
50-
}
51-
52-
return socket.readStop();
53-
}
54-
55-
function onshutdown(req) {
56-
let socket = this[owner_symbol];
57-
58-
if (socket.constructor.name === 'ReusedHandle') {
59-
socket = socket.handle;
60-
}
27+
function onreadstart() { return this[owner_symbol].readStart(); }
6128

62-
return socket.doShutdown(req);
63-
}
29+
function onreadstop() { return this[owner_symbol].readStop(); }
6430

65-
function onwrite(req, bufs) {
66-
let socket = this[owner_symbol];
31+
function onshutdown(req) { return this[owner_symbol].doShutdown(req); }
6732

68-
if (socket.constructor.name === 'ReusedHandle') {
69-
socket = socket.handle;
70-
}
71-
72-
return socket.doWrite(req, bufs);
73-
}
33+
function onwrite(req, bufs) { return this[owner_symbol].doWrite(req, bufs); }
7434

7535
/* This class serves as a wrapper for when the C++ side of Node wants access
7636
* to a standard JS stream. For example, TLS or HTTP do not operate on network

lib/internal/stream_base_commons.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ function handleWriteReq(req, data, encoding) {
8080
function onWriteComplete(status) {
8181
debug('onWriteComplete', status, this.error);
8282

83-
let stream = this.handle[owner_symbol];
84-
85-
if (stream.constructor.name === 'ReusedHandle') {
86-
stream = stream.handle;
87-
}
83+
const stream = this.handle[owner_symbol];
8884

8985
if (stream.destroyed) {
9086
if (typeof this.callback === 'function')
@@ -172,12 +168,7 @@ function onStreamRead(arrayBuffer) {
172168
const nread = streamBaseState[kReadBytesOrError];
173169

174170
const handle = this;
175-
176-
let stream = this[owner_symbol];
177-
178-
if (stream.constructor.name === 'ReusedHandle') {
179-
stream = stream.handle;
180-
}
171+
const stream = this[owner_symbol];
181172

182173
stream[kUpdateTimer]();
183174

lib/net.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1117,11 +1117,7 @@ Socket.prototype.unref = function() {
11171117

11181118

11191119
function afterConnect(status, handle, req, readable, writable) {
1120-
let self = handle[owner_symbol];
1121-
1122-
if (self.constructor.name === 'ReusedHandle') {
1123-
self = self.handle;
1124-
}
1120+
const self = handle[owner_symbol];
11251121

11261122
// Callback may come after call to destroy
11271123
if (self.destroyed) {

src/async_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void AsyncWrap::EmitDestroy(bool from_gc) {
313313

314314
if (!persistent().IsEmpty() && !from_gc) {
315315
HandleScope handle_scope(env()->isolate());
316-
USE(object()->Set(env()->context(), env()->owner_symbol(), object()));
316+
USE(object()->Set(env()->context(), env()->resource_symbol(), object()));
317317
}
318318
}
319319

@@ -589,7 +589,7 @@ void AsyncWrap::AsyncReset(Local<Object> resource, double execution_async_id,
589589
Local<Object> obj = object();
590590
CHECK(!obj.IsEmpty());
591591
if (resource != obj) {
592-
USE(obj->Set(env()->context(), env()->owner_symbol(), resource));
592+
USE(obj->Set(env()->context(), env()->resource_symbol(), resource));
593593
}
594594
}
595595

src/env.h

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ constexpr size_t kFsStatsBufferLength =
171171
V(oninit_symbol, "oninit") \
172172
V(owner_symbol, "owner_symbol") \
173173
V(onpskexchange_symbol, "onpskexchange") \
174+
V(resource_symbol, "resource_symbol") \
174175
V(trigger_async_id_symbol, "trigger_async_id_symbol") \
175176

176177
// Strings are per-isolate primitives but Environment proxies them

test/async-hooks/test-http-agent-handle-reuse-parallel.js

+2
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,6 @@ function onExit() {
8787
// Verify reuse handle has been wrapped
8888
assert.strictEqual(first.type, second.type);
8989
assert.ok(first.handle !== second.handle, 'Resource reused');
90+
assert.ok(first.handle === second.handle.handle,
91+
'Resource not wrapped correctly');
9092
}

test/async-hooks/test-http-agent-handle-reuse-serial.js

+2
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ function onExit() {
105105
// Verify reuse handle has been wrapped
106106
assert.strictEqual(first.type, second.type);
107107
assert.ok(first.handle !== second.handle, 'Resource reused');
108+
assert.ok(first.handle === second.handle.handle,
109+
'Resource not wrapped correctly');
108110
}

0 commit comments

Comments
 (0)