-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
async_hooks,process: remove internalNextTick #19147
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,10 @@ const common = require('_http_common'); | |
const checkIsHttpToken = common._checkIsHttpToken; | ||
const checkInvalidHeaderChar = common._checkInvalidHeaderChar; | ||
const { outHeadersKey } = require('internal/http'); | ||
const { async_id_symbol } = require('internal/async_hooks').symbols; | ||
const { nextTick } = require('internal/process/next_tick'); | ||
const { | ||
defaultTriggerAsyncIdScope, | ||
symbols: { async_id_symbol } | ||
} = require('internal/async_hooks'); | ||
const { | ||
ERR_HTTP_HEADERS_SENT, | ||
ERR_HTTP_INVALID_HEADER_VALUE, | ||
|
@@ -272,15 +274,14 @@ function _writeRaw(data, encoding, callback) { | |
this._flushOutput(conn); | ||
} else if (!data.length) { | ||
if (typeof callback === 'function') { | ||
let socketAsyncId = this.socket[async_id_symbol]; | ||
// If the socket was set directly it won't be correctly initialized | ||
// with an async_id_symbol. | ||
// TODO(AndreasMadsen): @trevnorris suggested some more correct | ||
// solutions in: | ||
// https://github.com/nodejs/node/pull/14389/files#r128522202 | ||
if (socketAsyncId === undefined) socketAsyncId = null; | ||
|
||
nextTick(socketAsyncId, callback); | ||
defaultTriggerAsyncIdScope(conn[async_id_symbol], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
process.nextTick, | ||
callback); | ||
} | ||
return true; | ||
} | ||
|
@@ -633,10 +634,13 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { | |
function write_(msg, chunk, encoding, callback, fromEnd) { | ||
if (msg.finished) { | ||
const err = new ERR_STREAM_WRITE_AFTER_END(); | ||
nextTick(msg.socket && msg.socket[async_id_symbol], | ||
writeAfterEndNT.bind(msg), | ||
err, | ||
callback); | ||
const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined; | ||
defaultTriggerAsyncIdScope(triggerAsyncId, | ||
process.nextTick, | ||
writeAfterEndNT, | ||
msg, | ||
err, | ||
callback); | ||
|
||
return true; | ||
} | ||
|
@@ -686,8 +690,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) { | |
} | ||
|
||
|
||
function writeAfterEndNT(err, callback) { | ||
this.emit('error', err); | ||
function writeAfterEndNT(msg, err, callback) { | ||
msg.emit('error', err); | ||
if (callback) callback(err); | ||
} | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This tests ensures that the triggerId of the nextTick function sets the | ||
// triggerAsyncId correctly. | ||
|
||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const initHooks = require('./init-hooks'); | ||
const { checkInvocations } = require('./hook-checks'); | ||
|
||
const hooks = initHooks(); | ||
hooks.enable(); | ||
|
||
const rootAsyncId = async_hooks.executionAsyncId(); | ||
|
||
process.nextTick(common.mustCall(function() { | ||
assert.strictEqual(async_hooks.triggerAsyncId(), rootAsyncId); | ||
})); | ||
|
||
process.on('exit', function() { | ||
hooks.sanityCheck(); | ||
|
||
const as = hooks.activitiesOfTypes('TickObject'); | ||
checkInvocations(as[0], { | ||
init: 1, before: 1, after: 1, destroy: 1 | ||
}, 'when process exits'); | ||
}); |
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.
After checking all the call sites, it's not possible to receive a
socket
here iferr
is truthy. (I've also double-checked this by adding an assert during debugging.)