errors: create internal connResetException
Replace various instances of errors that use code ECONNRESET with a single centralized factory function to create the errors. (While making changes to _tls_wrap.js, this also takes the opportunity to make trailing commas consistent on multi-line arrays. One had a trailing comma and one didn't. This adds a traiiling comma to the one that didn't.) PR-URL: https://github.com/nodejs/node/pull/27953 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
d05668d688
commit
aa8b820aaa
@ -40,13 +40,14 @@ const { Buffer } = require('buffer');
|
|||||||
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
|
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
|
||||||
const { URL, urlToOptions, searchParamsSymbol } = require('internal/url');
|
const { URL, urlToOptions, searchParamsSymbol } = require('internal/url');
|
||||||
const { outHeadersKey, ondrain } = require('internal/http');
|
const { outHeadersKey, ondrain } = require('internal/http');
|
||||||
|
const { connResetException, codes } = require('internal/errors');
|
||||||
const {
|
const {
|
||||||
ERR_HTTP_HEADERS_SENT,
|
ERR_HTTP_HEADERS_SENT,
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_INVALID_HTTP_TOKEN,
|
ERR_INVALID_HTTP_TOKEN,
|
||||||
ERR_INVALID_PROTOCOL,
|
ERR_INVALID_PROTOCOL,
|
||||||
ERR_UNESCAPED_CHARACTERS
|
ERR_UNESCAPED_CHARACTERS
|
||||||
} = require('internal/errors').codes;
|
} = codes;
|
||||||
const { getTimerDuration } = require('internal/timers');
|
const { getTimerDuration } = require('internal/timers');
|
||||||
const {
|
const {
|
||||||
DTRACE_HTTP_CLIENT_REQUEST,
|
DTRACE_HTTP_CLIENT_REQUEST,
|
||||||
@ -337,15 +338,6 @@ function emitAbortNT() {
|
|||||||
this.emit('abort');
|
this.emit('abort');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function createHangUpError() {
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
|
||||||
const error = new Error('socket hang up');
|
|
||||||
error.code = 'ECONNRESET';
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function socketCloseListener() {
|
function socketCloseListener() {
|
||||||
const socket = this;
|
const socket = this;
|
||||||
const req = socket._httpMessage;
|
const req = socket._httpMessage;
|
||||||
@ -381,7 +373,7 @@ function socketCloseListener() {
|
|||||||
// receive a response. The error needs to
|
// receive a response. The error needs to
|
||||||
// fire on the request.
|
// fire on the request.
|
||||||
req.socket._hadError = true;
|
req.socket._hadError = true;
|
||||||
req.emit('error', createHangUpError());
|
req.emit('error', connResetException('socket hang up'));
|
||||||
}
|
}
|
||||||
req.emit('close');
|
req.emit('close');
|
||||||
}
|
}
|
||||||
@ -441,7 +433,7 @@ function socketOnEnd() {
|
|||||||
// If we don't have a response then we know that the socket
|
// If we don't have a response then we know that the socket
|
||||||
// ended prematurely and we need to emit an error on the request.
|
// ended prematurely and we need to emit an error on the request.
|
||||||
req.socket._hadError = true;
|
req.socket._hadError = true;
|
||||||
req.emit('error', createHangUpError());
|
req.emit('error', connResetException('socket hang up'));
|
||||||
}
|
}
|
||||||
if (parser) {
|
if (parser) {
|
||||||
parser.finish();
|
parser.finish();
|
||||||
|
@ -44,6 +44,7 @@ const tls_wrap = internalBinding('tls_wrap');
|
|||||||
const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
|
const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
|
||||||
const { owner_symbol } = require('internal/async_hooks').symbols;
|
const { owner_symbol } = require('internal/async_hooks').symbols;
|
||||||
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
|
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
|
||||||
|
const { connResetException, codes } = require('internal/errors');
|
||||||
const {
|
const {
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_INVALID_CALLBACK,
|
ERR_INVALID_CALLBACK,
|
||||||
@ -55,7 +56,7 @@ const {
|
|||||||
ERR_TLS_REQUIRED_SERVER_NAME,
|
ERR_TLS_REQUIRED_SERVER_NAME,
|
||||||
ERR_TLS_SESSION_ATTACK,
|
ERR_TLS_SESSION_ATTACK,
|
||||||
ERR_TLS_SNI_FROM_SERVER
|
ERR_TLS_SNI_FROM_SERVER
|
||||||
} = require('internal/errors').codes;
|
} = codes;
|
||||||
const { getOptionValue } = require('internal/options');
|
const { getOptionValue } = require('internal/options');
|
||||||
const { validateString } = require('internal/validators');
|
const { validateString } = require('internal/validators');
|
||||||
const traceTls = getOptionValue('--trace-tls');
|
const traceTls = getOptionValue('--trace-tls');
|
||||||
@ -442,7 +443,7 @@ const proxiedMethods = [
|
|||||||
'setSimultaneousAccepts', 'setBlocking',
|
'setSimultaneousAccepts', 'setBlocking',
|
||||||
|
|
||||||
// PipeWrap
|
// PipeWrap
|
||||||
'setPendingInstances'
|
'setPendingInstances',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Proxy HandleWrap, PipeWrap and TCPWrap methods
|
// Proxy HandleWrap, PipeWrap and TCPWrap methods
|
||||||
@ -908,9 +909,7 @@ function onSocketClose(err) {
|
|||||||
// Emit ECONNRESET
|
// Emit ECONNRESET
|
||||||
if (!this._controlReleased && !this[kErrorEmitted]) {
|
if (!this._controlReleased && !this[kErrorEmitted]) {
|
||||||
this[kErrorEmitted] = true;
|
this[kErrorEmitted] = true;
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
const connReset = connResetException('socket hang up');
|
||||||
const connReset = new Error('socket hang up');
|
|
||||||
connReset.code = 'ECONNRESET';
|
|
||||||
this._tlsOptions.server.emit('tlsClientError', connReset, this);
|
this._tlsOptions.server.emit('tlsClientError', connReset, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1353,10 +1352,9 @@ function onConnectEnd() {
|
|||||||
if (!this._hadError) {
|
if (!this._hadError) {
|
||||||
const options = this[kConnectOptions];
|
const options = this[kConnectOptions];
|
||||||
this._hadError = true;
|
this._hadError = true;
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
const error = connResetException('Client network socket disconnected ' +
|
||||||
const error = new Error('Client network socket disconnected before ' +
|
'before secure TLS connection was ' +
|
||||||
'secure TLS connection was established');
|
'established');
|
||||||
error.code = 'ECONNRESET';
|
|
||||||
error.path = options.path;
|
error.path = options.path;
|
||||||
error.host = options.host;
|
error.host = options.host;
|
||||||
error.port = options.port;
|
error.port = options.port;
|
||||||
|
@ -554,6 +554,13 @@ function dnsException(code, syscall, hostname) {
|
|||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function connResetException(msg) {
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
const ex = new Error(msg);
|
||||||
|
ex.code = 'ECONNRESET';
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
|
|
||||||
let maxStack_ErrorName;
|
let maxStack_ErrorName;
|
||||||
let maxStack_ErrorMessage;
|
let maxStack_ErrorMessage;
|
||||||
/**
|
/**
|
||||||
@ -619,6 +626,7 @@ module.exports = {
|
|||||||
getMessage,
|
getMessage,
|
||||||
hideStackFrames,
|
hideStackFrames,
|
||||||
isStackOverflowError,
|
isStackOverflowError,
|
||||||
|
connResetException,
|
||||||
uvException,
|
uvException,
|
||||||
uvExceptionWithHostPort,
|
uvExceptionWithHostPort,
|
||||||
SystemError,
|
SystemError,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user