From 65b1cba6a1591af9cc16b0efbb5a53f2b8fa08ba Mon Sep 17 00:00:00 2001 From: Daniel Schopper Date: Fri, 8 Feb 2019 11:32:41 +0100 Subject: [PATCH 1/3] Attempt to fix defaultEvictor. If `pooledResource` is not a `Resource` (but an `Error`), it won't have `lastIdleTime` thus all ifs are returning `false` meaning the `Resource` (which is already broken in some way) won't get evicted ever, they stay in the pool and this may result in a `ResourceRequest Timed Out` error (b/c all slots are occupied by stuck `Resource`s). As a solution, `idleTime` is checked, and if it is falsy, the `Resource` gets evicted. Signed-off-by: Daniel Schopper --- lib/DefaultEvictor.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/DefaultEvictor.js b/lib/DefaultEvictor.js index 658d345a..6992aee1 100644 --- a/lib/DefaultEvictor.js +++ b/lib/DefaultEvictor.js @@ -1,23 +1,31 @@ "use strict"; class DefaultEvictor { - evict(config, pooledResource, availableObjectsCount) { - const idleTime = Date.now() - pooledResource.lastIdleTime; + evict(config, pooledResource, availableObjectsCount) { + const idleTime = Date.now() - pooledResource.lastIdleTime; - if ( - config.softIdleTimeoutMillis > 0 && - config.softIdleTimeoutMillis < idleTime && - config.min < availableObjectsCount - ) { - return true; - } + if (!idleTime) { + console.log('ERROR - idleTime is junk, evictig!', JSON.stringify({ + idleTime, + pooledResource, + })); + return true; + } - if (config.idleTimeoutMillis < idleTime) { - return true; - } + if ( + config.softIdleTimeoutMillis > 0 && + config.softIdleTimeoutMillis < idleTime && + config.min < availableObjectsCount + ) { + return true; + } - return false; - } + if (config.idleTimeoutMillis < idleTime) { + return true; + } + + return false; + } } module.exports = DefaultEvictor; From ea3333876231ba76b2664ea70c66be7c49129a58 Mon Sep 17 00:00:00 2001 From: Daniel Schopper Date: Sun, 10 Feb 2019 22:08:10 +0100 Subject: [PATCH 2/3] fix TravisCI eslint errors --- lib/DefaultEvictor.js | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/DefaultEvictor.js b/lib/DefaultEvictor.js index 6992aee1..61b3fb84 100644 --- a/lib/DefaultEvictor.js +++ b/lib/DefaultEvictor.js @@ -1,31 +1,33 @@ "use strict"; class DefaultEvictor { - evict(config, pooledResource, availableObjectsCount) { - const idleTime = Date.now() - pooledResource.lastIdleTime; + evict(config, pooledResource, availableObjectsCount) { + const idleTime = Date.now() - pooledResource.lastIdleTime; - if (!idleTime) { - console.log('ERROR - idleTime is junk, evictig!', JSON.stringify({ - idleTime, - pooledResource, - })); - return true; - } - - if ( - config.softIdleTimeoutMillis > 0 && - config.softIdleTimeoutMillis < idleTime && - config.min < availableObjectsCount - ) { - return true; - } + if (!idleTime) { + console.log( + "ERROR - idleTime is junk, evictig", + JSON.stringify({ + idleTime, + pooledResource + })); + return true; + } - if (config.idleTimeoutMillis < idleTime) { - return true; - } + if ( + config.softIdleTimeoutMillis > 0 && + config.softIdleTimeoutMillis < idleTime && + config.min < availableObjectsCount + ) { + return true; + } - return false; + if (config.idleTimeoutMillis < idleTime) { + return true; } + + return false; + } } module.exports = DefaultEvictor; From dd00bb9434db6c9a378118f7b36f5e190416ea4a Mon Sep 17 00:00:00 2001 From: Daniel Schopper Date: Tue, 30 Apr 2019 14:38:02 +0200 Subject: [PATCH 3/3] changed `JSON.stringify` to `util.inspect` as `stringify` throws `TypeError: Converting circular structure to JSON` error Signed-off-by: Daniel Schopper --- lib/DefaultEvictor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/DefaultEvictor.js b/lib/DefaultEvictor.js index 61b3fb84..83de63ca 100644 --- a/lib/DefaultEvictor.js +++ b/lib/DefaultEvictor.js @@ -1,4 +1,5 @@ "use strict"; +const util = require('util'); class DefaultEvictor { evict(config, pooledResource, availableObjectsCount) { @@ -7,7 +8,7 @@ class DefaultEvictor { if (!idleTime) { console.log( "ERROR - idleTime is junk, evictig", - JSON.stringify({ + util.inspect({ idleTime, pooledResource }));