Skip to content
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

errors: create internal connResetException #27953

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ const { Buffer } = require('buffer');
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
const { URL, urlToOptions, searchParamsSymbol } = require('internal/url');
const { outHeadersKey, ondrain } = require('internal/http');
const { connResetException, codes } = require('internal/errors');
const {
ERR_HTTP_HEADERS_SENT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_HTTP_TOKEN,
ERR_INVALID_PROTOCOL,
ERR_UNESCAPED_CHARACTERS
} = require('internal/errors').codes;
} = codes;
const { getTimerDuration } = require('internal/timers');
const {
DTRACE_HTTP_CLIENT_REQUEST,
Expand Down Expand Up @@ -337,15 +338,6 @@ function emitAbortNT() {
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() {
const socket = this;
const req = socket._httpMessage;
Expand Down Expand Up @@ -381,7 +373,7 @@ function socketCloseListener() {
// receive a response. The error needs to
// fire on the request.
req.socket._hadError = true;
req.emit('error', createHangUpError());
req.emit('error', connResetException('socket hang up'));
}
req.emit('close');
}
Expand Down Expand Up @@ -441,7 +433,7 @@ function socketOnEnd() {
// 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.
req.socket._hadError = true;
req.emit('error', createHangUpError());
req.emit('error', connResetException('socket hang up'));
}
if (parser) {
parser.finish();
Expand Down
16 changes: 7 additions & 9 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const tls_wrap = internalBinding('tls_wrap');
const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
const { owner_symbol } = require('internal/async_hooks').symbols;
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
const { connResetException, codes } = require('internal/errors');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK,
Expand All @@ -55,7 +56,7 @@ const {
ERR_TLS_REQUIRED_SERVER_NAME,
ERR_TLS_SESSION_ATTACK,
ERR_TLS_SNI_FROM_SERVER
} = require('internal/errors').codes;
} = codes;
const { getOptionValue } = require('internal/options');
const { validateString } = require('internal/validators');
const traceTls = getOptionValue('--trace-tls');
Expand Down Expand Up @@ -442,7 +443,7 @@ const proxiedMethods = [
'setSimultaneousAccepts', 'setBlocking',

// PipeWrap
'setPendingInstances'
'setPendingInstances',
];

// Proxy HandleWrap, PipeWrap and TCPWrap methods
Expand Down Expand Up @@ -908,9 +909,7 @@ function onSocketClose(err) {
// Emit ECONNRESET
if (!this._controlReleased && !this[kErrorEmitted]) {
this[kErrorEmitted] = true;
// eslint-disable-next-line no-restricted-syntax
const connReset = new Error('socket hang up');
connReset.code = 'ECONNRESET';
const connReset = connResetException('socket hang up');
this._tlsOptions.server.emit('tlsClientError', connReset, this);
}
}
Expand Down Expand Up @@ -1353,10 +1352,9 @@ function onConnectEnd() {
if (!this._hadError) {
const options = this[kConnectOptions];
this._hadError = true;
// eslint-disable-next-line no-restricted-syntax
const error = new Error('Client network socket disconnected before ' +
'secure TLS connection was established');
error.code = 'ECONNRESET';
const error = connResetException('Client network socket disconnected ' +
'before secure TLS connection was ' +
'established');
error.path = options.path;
error.host = options.host;
error.port = options.port;
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ function dnsException(code, syscall, hostname) {
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_ErrorMessage;
/**
Expand Down Expand Up @@ -619,6 +626,7 @@ module.exports = {
getMessage,
hideStackFrames,
isStackOverflowError,
connResetException,
uvException,
uvExceptionWithHostPort,
SystemError,
Expand Down