-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process: deprecate _getActive*
private APIs in favour of async_hooks
#40804
Closed
RaisinTen
wants to merge
1
commit into
nodejs:master
from
RaisinTen:remove-_getActive-functions-in-favour-of-async_hooks
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should leave the actual test in place since we're not removing these APIs yet.