mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
e9ac80bb39
Instead of exposing internals of async_hooks & async_wrap throughout the code base, create necessary helper methods within the internal async_hooks that allows easy usage by Node.js internals. This stops every single internal user of async_hooks from importing a ton of functions, constants and internal Aliased Buffers from C++ async_wrap. Adds functions initHooksExist, afterHooksExist, and destroyHooksExist to determine whether the related emit methods need to be triggered. Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side as an alternative to always calling C++. Moves async_id_symbol and trigger_async_id_symbol to internal async_hooks as they are never used in C++. Renames newUid to newAsyncId for added clarity of its purpose. Adjusts usage throughout the codebase, as well as in a couple of tests. PR-URL: https://github.com/nodejs/node/pull/18720 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
44 lines
1004 B
JavaScript
44 lines
1004 B
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
// Make sure http.request() can catch immediate errors in
|
|
// net.createConnection().
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
const http = require('http');
|
|
const uv = process.binding('uv');
|
|
const {
|
|
newAsyncId,
|
|
symbols: { async_id_symbol }
|
|
} = require('internal/async_hooks');
|
|
|
|
const agent = new http.Agent();
|
|
agent.createConnection = common.mustCall((cfg) => {
|
|
const sock = new net.Socket();
|
|
|
|
// Fake the handle so we can enforce returning an immediate error
|
|
sock._handle = {
|
|
connect: common.mustCall((req, addr, port) => {
|
|
return uv.UV_ENETUNREACH;
|
|
}),
|
|
readStart() {},
|
|
close() {}
|
|
};
|
|
|
|
// Simulate just enough socket handle initialization
|
|
sock[async_id_symbol] = newAsyncId();
|
|
|
|
sock.connect(cfg);
|
|
return sock;
|
|
});
|
|
|
|
http.get({
|
|
host: '127.0.0.1',
|
|
port: 1,
|
|
agent
|
|
}).on('error', common.mustCall((err) => {
|
|
assert.strictEqual(err.code, 'ENETUNREACH');
|
|
}));
|