From 1275d01098821ec59b00fc860a7cf611e735916f Mon Sep 17 00:00:00 2001 From: Tyler Smalley Date: Thu, 14 Mar 2019 15:30:06 -0700 Subject: [PATCH] [logging] Corrects intercept of ECONNRESET (#31742) (#32247) errno is not set for ECONNRESET https://github.com/hapijs/wreck/blob/29d8f4b5eaa12c5d44c642130cd6002c1d83ffd2/lib/index.js#L290 Closes https://github.com/elastic/kibana/issues/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 --- src/server/logging/log_interceptor.js | 8 +++++--- src/server/logging/log_interceptor.test.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/server/logging/log_interceptor.js b/src/server/logging/log_interceptor.js index eaddae122aa49..040c0b99442a3 100644 --- a/src/server/logging/log_interceptor.js +++ b/src/server/logging/log_interceptor.js @@ -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(); @@ -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) { diff --git a/src/server/logging/log_interceptor.test.js b/src/server/logging/log_interceptor.test.js index 43290f9b49737..e56f2f1477eda 100644 --- a/src/server/logging/log_interceptor.test.js +++ b/src/server/logging/log_interceptor.test.js @@ -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' });