-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: deprecate
_getActive*
private APIs in favour of async_hooks
The `process._getActiveRequests()` and `process._getActiveHandles()` functions are not needed anymore because the `async_hooks` module already provides functionality that helps us to keep a track of the active resources. Signed-off-by: Darshan Sen <[email protected]>
- Loading branch information
Showing
8 changed files
with
151 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const net = require('net'); | ||
|
||
const activeHandles = new Map(); | ||
async_hooks.createHook({ | ||
init(asyncId, type, triggerAsyncId, resource) { | ||
if (['TCPSERVERWRAP', 'TCPWRAP'].includes(type)) | ||
activeHandles.set(asyncId, resource); | ||
}, | ||
destroy(asyncId) { | ||
activeHandles.delete(asyncId); | ||
} | ||
}).enable(); | ||
|
||
const NUM = 8; | ||
const connections = []; | ||
const clients = []; | ||
let clients_counter = 0; | ||
|
||
const server = net.createServer(function listener(c) { | ||
connections.push(c); | ||
}).listen(0, makeConnection); | ||
|
||
|
||
function makeConnection() { | ||
if (clients_counter >= NUM) return; | ||
net.connect(server.address().port, function connected() { | ||
clientConnected(this); | ||
makeConnection(); | ||
}); | ||
} | ||
|
||
|
||
function clientConnected(client) { | ||
clients.push(client); | ||
if (++clients_counter >= NUM) | ||
checkAll(); | ||
} | ||
|
||
|
||
function checkAll() { | ||
const handles = Array.from(activeHandles.values()); | ||
|
||
clients.forEach(function(item) { | ||
assert.ok(handles.includes(item._handle)); | ||
item.destroy(); | ||
}); | ||
|
||
connections.forEach(function(item) { | ||
assert.ok(handles.includes(item._handle)); | ||
item.end(); | ||
}); | ||
|
||
assert.ok(handles.includes(server._handle)); | ||
server.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const fs = require('fs'); | ||
|
||
let numFsReqCallbacks = 0; | ||
async_hooks.createHook({ | ||
init(asyncId, type, triggerAsyncId, resource) { | ||
if (type === 'FSREQCALLBACK') | ||
++numFsReqCallbacks; | ||
}, | ||
destroy(asyncId) { | ||
--numFsReqCallbacks; | ||
} | ||
}).enable(); | ||
|
||
for (let i = 0; i < 12; i++) | ||
fs.open(__filename, 'r', common.mustCall()); | ||
|
||
assert.strictEqual(numFsReqCallbacks, 12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,11 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const NUM = 8; | ||
const connections = []; | ||
const clients = []; | ||
let clients_counter = 0; | ||
const { expectWarning } = require('../common'); | ||
|
||
const server = net.createServer(function listener(c) { | ||
connections.push(c); | ||
}).listen(0, makeConnection); | ||
expectWarning( | ||
'DeprecationWarning', | ||
'process._getActiveHandles() is deprecated. Please use the `async_hooks` ' + | ||
'module instead.', | ||
'DEP0157'); | ||
|
||
|
||
function makeConnection() { | ||
if (clients_counter >= NUM) return; | ||
net.connect(server.address().port, function connected() { | ||
clientConnected(this); | ||
makeConnection(); | ||
}); | ||
} | ||
|
||
|
||
function clientConnected(client) { | ||
clients.push(client); | ||
if (++clients_counter >= NUM) | ||
checkAll(); | ||
} | ||
|
||
|
||
function checkAll() { | ||
const handles = process._getActiveHandles(); | ||
|
||
clients.forEach(function(item) { | ||
assert.ok(handles.includes(item)); | ||
item.destroy(); | ||
}); | ||
|
||
connections.forEach(function(item) { | ||
assert.ok(handles.includes(item)); | ||
item.end(); | ||
}); | ||
|
||
assert.ok(handles.includes(server)); | ||
server.close(); | ||
} | ||
process._getActiveHandles(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const { expectWarning } = require('../common'); | ||
|
||
for (let i = 0; i < 12; i++) | ||
fs.open(__filename, 'r', common.mustCall()); | ||
expectWarning( | ||
'DeprecationWarning', | ||
'process._getActiveRequests() is deprecated. Please use the `async_hooks` ' + | ||
'module instead.', | ||
'DEP0157'); | ||
|
||
assert.strictEqual(process._getActiveRequests().length, 12); | ||
process._getActiveRequests(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters