Skip to content

Commit

Permalink
[logging] Corrects intercept of ECONNRESET (elastic#31742)
Browse files Browse the repository at this point in the history
errno is not set for ECONNRESET

https://github.com/hapijs/wreck/blob/29d8f4b5eaa12c5d44c642130cd6002c1d83ffd2/lib/index.js#L290

Closes elastic#22225

Example:

{ Error: socket hang up
  at TLSSocket.onSocketClose (_tls_wrap.js:761:23)
  at TLSSocket.emit (events.js:194:15)
  at _handle.close (net.js:600:12)
  at Socket.done (_tls_wrap.js:388:7)
  at Object.onceWrapper (events.js:277:13)
  at Socket.emit (events.js:189:13)
  at TCP._handle.close (net.js:600:12) code: 'ECONNRESET'

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
tylersmalley authored and Tyler Smalley committed Feb 23, 2019
1 parent f561ff1 commit fb932a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/legacy/server/logging/log_interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ function doesMessageMatch(errorMessage, match) {
if (isRegExp) return match.test(errorMessage);
return errorMessage === match;
}

// converts the given event into a debug log if it's an error of the given type
function downgradeIfErrorType(errorType, event, field = 'errno') {
function downgradeIfErrorType(errorType, event) {
const isClientError = doTagsMatch(event, ['connection', 'client', 'error']);
const matchesErrorType = isClientError && get(event, `error.${field}`) === errorType;
if (!isClientError) return null;

const matchesErrorType = get(event, 'error.code') === errorType || get(event, 'error.errno') === errorType;
if (!matchesErrorType) return null;

const errorTypeTag = errorType.toLowerCase();
Expand Down Expand Up @@ -117,7 +119,7 @@ export class LogInterceptor extends Stream.Transform {
}

downgradeIfHTTPSWhenHTTP(event) {
return downgradeIfErrorType('HPE_INVALID_METHOD', event, 'code');
return downgradeIfErrorType('HPE_INVALID_METHOD', event);
}

downgradeIfHTTPWhenHTTPS(event) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/logging/log_interceptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function stubClientErrorEvent(errorMeta) {
};
}

const stubEconnresetEvent = () => stubClientErrorEvent({ errno: 'ECONNRESET' });
const stubEconnresetEvent = () => stubClientErrorEvent({ code: 'ECONNRESET' });
const stubEpipeEvent = () => stubClientErrorEvent({ errno: 'EPIPE' });
const stubEcanceledEvent = () => stubClientErrorEvent({ errno: 'ECANCELED' });

Expand Down

0 comments on commit fb932a8

Please sign in to comment.