From a54f2ac5405aca1417bec254475fd899db3f002e Mon Sep 17 00:00:00 2001 From: Tony Ko Date: Mon, 27 May 2019 06:20:58 -0400 Subject: [PATCH] Close DB connection when underlining app throws an exception Wrapper does not close connection when next() fails. Leaves many connections hanging open --- src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 4423999..2b59541 100644 --- a/src/index.js +++ b/src/index.js @@ -59,7 +59,12 @@ module.exports = function(conn, options){ return err; } - await next(); - db.pool.end(); + try { + await next(); + db.pool.end(); + }catch(err){ + db.pool.end(); + throw err; + } } }