Revert "async_hooks: merge resource_symbol with owner_symbol"
This reverts commit 7ca2f1303996e0c79c354e979a1527da444ca886. PR-URL: https://github.com/nodejs/node/pull/40741 Fixes: https://github.com/nodejs/node/issues/40693 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
ff3989572a
commit
2b0087f3d4
@ -525,7 +525,7 @@ function asyncResetHandle(socket) {
|
|||||||
const handle = socket._handle;
|
const handle = socket._handle;
|
||||||
if (handle && typeof handle.asyncReset === 'function') {
|
if (handle && typeof handle.asyncReset === 'function') {
|
||||||
// Assign the handle a new asyncId and run any destroy()/init() hooks.
|
// Assign the handle a new asyncId and run any destroy()/init() hooks.
|
||||||
handle.asyncReset(new ReusedHandle(handle.getProviderType(), socket));
|
handle.asyncReset(new ReusedHandle(handle.getProviderType(), handle));
|
||||||
socket[async_id_symbol] = handle.getAsyncId();
|
socket[async_id_symbol] = handle.getAsyncId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ const active_hooks = {
|
|||||||
|
|
||||||
const { registerDestroyHook } = async_wrap;
|
const { registerDestroyHook } = async_wrap;
|
||||||
const { enqueueMicrotask } = internalBinding('task_queue');
|
const { enqueueMicrotask } = internalBinding('task_queue');
|
||||||
const { owner_symbol } = internalBinding('symbols');
|
const { resource_symbol, owner_symbol } = internalBinding('symbols');
|
||||||
|
|
||||||
// Each constant tracks how many callbacks there are for any given step of
|
// Each constant tracks how many callbacks there are for any given step of
|
||||||
// async execution. These are tracked so if the user didn't include callbacks
|
// async execution. These are tracked so if the user didn't include callbacks
|
||||||
@ -176,13 +176,11 @@ function fatalError(e) {
|
|||||||
|
|
||||||
function lookupPublicResource(resource) {
|
function lookupPublicResource(resource) {
|
||||||
if (typeof resource !== 'object' || resource === null) return resource;
|
if (typeof resource !== 'object' || resource === null) return resource;
|
||||||
|
// TODO(addaleax): Merge this with owner_symbol and use it across all
|
||||||
const publicResource = resource[owner_symbol];
|
// AsyncWrap instances.
|
||||||
|
const publicResource = resource[resource_symbol];
|
||||||
if (publicResource != null) {
|
if (publicResource !== undefined)
|
||||||
return publicResource;
|
return publicResource;
|
||||||
}
|
|
||||||
|
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,55 +22,15 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
|
|||||||
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
|
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
|
||||||
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');
|
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');
|
||||||
|
|
||||||
function isClosing() {
|
function isClosing() { return this[owner_symbol].isClosing(); }
|
||||||
let socket = this[owner_symbol];
|
|
||||||
|
|
||||||
if (socket.constructor.name === 'ReusedHandle') {
|
function onreadstart() { return this[owner_symbol].readStart(); }
|
||||||
socket = socket.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return socket.isClosing();
|
function onreadstop() { return this[owner_symbol].readStop(); }
|
||||||
}
|
|
||||||
|
|
||||||
function onreadstart() {
|
function onshutdown(req) { return this[owner_symbol].doShutdown(req); }
|
||||||
let socket = this[owner_symbol];
|
|
||||||
|
|
||||||
if (socket.constructor.name === 'ReusedHandle') {
|
function onwrite(req, bufs) { return this[owner_symbol].doWrite(req, bufs); }
|
||||||
socket = socket.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return socket.readStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onreadstop() {
|
|
||||||
let socket = this[owner_symbol];
|
|
||||||
|
|
||||||
if (socket.constructor.name === 'ReusedHandle') {
|
|
||||||
socket = socket.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return socket.readStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onshutdown(req) {
|
|
||||||
let socket = this[owner_symbol];
|
|
||||||
|
|
||||||
if (socket.constructor.name === 'ReusedHandle') {
|
|
||||||
socket = socket.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return socket.doShutdown(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onwrite(req, bufs) {
|
|
||||||
let socket = this[owner_symbol];
|
|
||||||
|
|
||||||
if (socket.constructor.name === 'ReusedHandle') {
|
|
||||||
socket = socket.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
return socket.doWrite(req, bufs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This class serves as a wrapper for when the C++ side of Node wants access
|
/* This class serves as a wrapper for when the C++ side of Node wants access
|
||||||
* to a standard JS stream. For example, TLS or HTTP do not operate on network
|
* to a standard JS stream. For example, TLS or HTTP do not operate on network
|
||||||
|
@ -80,11 +80,7 @@ function handleWriteReq(req, data, encoding) {
|
|||||||
function onWriteComplete(status) {
|
function onWriteComplete(status) {
|
||||||
debug('onWriteComplete', status, this.error);
|
debug('onWriteComplete', status, this.error);
|
||||||
|
|
||||||
let stream = this.handle[owner_symbol];
|
const stream = this.handle[owner_symbol];
|
||||||
|
|
||||||
if (stream.constructor.name === 'ReusedHandle') {
|
|
||||||
stream = stream.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stream.destroyed) {
|
if (stream.destroyed) {
|
||||||
if (typeof this.callback === 'function')
|
if (typeof this.callback === 'function')
|
||||||
@ -172,12 +168,7 @@ function onStreamRead(arrayBuffer) {
|
|||||||
const nread = streamBaseState[kReadBytesOrError];
|
const nread = streamBaseState[kReadBytesOrError];
|
||||||
|
|
||||||
const handle = this;
|
const handle = this;
|
||||||
|
const stream = this[owner_symbol];
|
||||||
let stream = this[owner_symbol];
|
|
||||||
|
|
||||||
if (stream.constructor.name === 'ReusedHandle') {
|
|
||||||
stream = stream.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream[kUpdateTimer]();
|
stream[kUpdateTimer]();
|
||||||
|
|
||||||
|
@ -1117,11 +1117,7 @@ Socket.prototype.unref = function() {
|
|||||||
|
|
||||||
|
|
||||||
function afterConnect(status, handle, req, readable, writable) {
|
function afterConnect(status, handle, req, readable, writable) {
|
||||||
let self = handle[owner_symbol];
|
const self = handle[owner_symbol];
|
||||||
|
|
||||||
if (self.constructor.name === 'ReusedHandle') {
|
|
||||||
self = self.handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback may come after call to destroy
|
// Callback may come after call to destroy
|
||||||
if (self.destroyed) {
|
if (self.destroyed) {
|
||||||
|
@ -313,7 +313,7 @@ void AsyncWrap::EmitDestroy(bool from_gc) {
|
|||||||
|
|
||||||
if (!persistent().IsEmpty() && !from_gc) {
|
if (!persistent().IsEmpty() && !from_gc) {
|
||||||
HandleScope handle_scope(env()->isolate());
|
HandleScope handle_scope(env()->isolate());
|
||||||
USE(object()->Set(env()->context(), env()->owner_symbol(), object()));
|
USE(object()->Set(env()->context(), env()->resource_symbol(), object()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ void AsyncWrap::AsyncReset(Local<Object> resource, double execution_async_id,
|
|||||||
Local<Object> obj = object();
|
Local<Object> obj = object();
|
||||||
CHECK(!obj.IsEmpty());
|
CHECK(!obj.IsEmpty());
|
||||||
if (resource != obj) {
|
if (resource != obj) {
|
||||||
USE(obj->Set(env()->context(), env()->owner_symbol(), resource));
|
USE(obj->Set(env()->context(), env()->resource_symbol(), resource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +171,7 @@ constexpr size_t kFsStatsBufferLength =
|
|||||||
V(oninit_symbol, "oninit") \
|
V(oninit_symbol, "oninit") \
|
||||||
V(owner_symbol, "owner_symbol") \
|
V(owner_symbol, "owner_symbol") \
|
||||||
V(onpskexchange_symbol, "onpskexchange") \
|
V(onpskexchange_symbol, "onpskexchange") \
|
||||||
|
V(resource_symbol, "resource_symbol") \
|
||||||
V(trigger_async_id_symbol, "trigger_async_id_symbol") \
|
V(trigger_async_id_symbol, "trigger_async_id_symbol") \
|
||||||
|
|
||||||
// Strings are per-isolate primitives but Environment proxies them
|
// Strings are per-isolate primitives but Environment proxies them
|
||||||
|
@ -87,4 +87,6 @@ function onExit() {
|
|||||||
// Verify reuse handle has been wrapped
|
// Verify reuse handle has been wrapped
|
||||||
assert.strictEqual(first.type, second.type);
|
assert.strictEqual(first.type, second.type);
|
||||||
assert.ok(first.handle !== second.handle, 'Resource reused');
|
assert.ok(first.handle !== second.handle, 'Resource reused');
|
||||||
|
assert.ok(first.handle === second.handle.handle,
|
||||||
|
'Resource not wrapped correctly');
|
||||||
}
|
}
|
||||||
|
@ -105,4 +105,6 @@ function onExit() {
|
|||||||
// Verify reuse handle has been wrapped
|
// Verify reuse handle has been wrapped
|
||||||
assert.strictEqual(first.type, second.type);
|
assert.strictEqual(first.type, second.type);
|
||||||
assert.ok(first.handle !== second.handle, 'Resource reused');
|
assert.ok(first.handle !== second.handle, 'Resource reused');
|
||||||
|
assert.ok(first.handle === second.handle.handle,
|
||||||
|
'Resource not wrapped correctly');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user