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: #40741Fixes: #40693 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent b614b17 commit 48157c4

9 files changed

Lines changed: 21 additions & 71 deletions

‎lib/_http_agent.js‎

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

‎lib/internal/async_hooks.js‎

Lines changed: 5 additions & 7 deletions
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
functionlookupPublicResource(resource){
178178
if(typeofresource!=='object'||resource===null)returnresource;
179-
180-
constpublicResource=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+
constpublicResource=resource[resource_symbol];
182+
if(publicResource!==undefined)
183183
returnpublicResource;
184-
}
185-
186184
returnresource;
187185
}
188186

‎lib/internal/js_stream_socket.js‎

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,15 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
2222
constkCurrentShutdownRequest=Symbol('kCurrentShutdownRequest');
2323
constkPendingShutdownRequest=Symbol('kPendingShutdownRequest');
2424

25-
functionisClosing(){
26-
letsocket=this[owner_symbol];
25+
functionisClosing(){returnthis[owner_symbol].isClosing();}
2726

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

62-
returnsocket.doShutdown(req);
63-
}
29+
functiononreadstop(){returnthis[owner_symbol].readStop();}
6430

65-
functiononwrite(req,bufs){
66-
letsocket=this[owner_symbol];
31+
functiononshutdown(req){returnthis[owner_symbol].doShutdown(req);}
6732

68-
if(socket.constructor.name==='ReusedHandle'){
69-
socket=socket.handle;
70-
}
71-
72-
returnsocket.doWrite(req,bufs);
73-
}
33+
functiononwrite(req,bufs){returnthis[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‎

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

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

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

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

182173
stream[kUpdateTimer]();
183174

‎lib/net.js‎

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

11181118

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

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

‎src/async_wrap.cc‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 2 additions & 0 deletions
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)