From 694d3f630edb286ba5b1169906adf2e5edc986de Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 5 Jul 2021 06:07:40 +0200 Subject: [PATCH] SessionStore: Propagate database errors to express-session Send a 500 HTTP status code to the client if the session entry could not be fetched from the database. This is useful in case the database is busy and can't respond to the query in time. In this case we want to abort the client connection as soon as possible. Co-authored-by: Richard Hansen --- src/node/db/SessionStore.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/node/db/SessionStore.js b/src/node/db/SessionStore.js index 2c5d1ca25..d06754fdd 100644 --- a/src/node/db/SessionStore.js +++ b/src/node/db/SessionStore.js @@ -17,18 +17,12 @@ const logger = log4js.getLogger('SessionStore'); module.exports = class SessionStore extends Store { get(sid, fn) { logger.debug(`GET ${sid}`); - DB.db.get(`sessionstorage:${sid}`, (err, sess) => { - if (sess) { - sess.cookie.expires = ('string' === typeof sess.cookie.expires - ? new Date(sess.cookie.expires) : sess.cookie.expires); - if (!sess.cookie.expires || new Date() < sess.cookie.expires) { - fn(null, sess); - } else { - this.destroy(sid, fn); - } - } else { - fn(); - } + DB.db.get(`sessionstorage:${sid}`, (err, s) => { + if (err != null) return fn(err); + if (!s) return fn(null); + if (typeof s.cookie.expires === 'string') s.cookie.expires = new Date(s.cookie.expires); + if (s.cookie.expires && new Date() >= s.cookie.expires) return this.destroy(sid, fn); + fn(null, s); }); }