voxpelli / node-connect-pg-simple

A simple, minimal PostgreSQL session store for Express
https://www.npmjs.com/package/connect-pg-simple
MIT License
234 stars 74 forks source link

Initialize pruning lazily #285

Closed voxpelli closed 1 year ago

voxpelli commented 1 year ago

I think the proper solution to #268 and #269 is to ensure that we wait for the web server to be fully started and accepting incoming requests before we start to clean anything.

When the web server is accepting requests, then the database should be ready and any calls to it should be able to properly create the database.

This also removes a thundering herd problem when multiple instances are brought up simultaneously, as previously they would all start pruning session at once on startup (when auto-pruning was configured), putting unnecessary load on the database.

I think this solution is preferable to #269 as failure to create database is quite a critical condition and shouldn't have to be retried. If the database can't be created, then no web requests can actually be handled.

Previously it could fail because the prune job tried to eagerly create it, but with this PR that will no longer be the case.

janbusch commented 1 year ago

Don't know how many people really implement and monitor the ready state of their app with database health checks, but since we do, this is fine for me ;)

voxpelli commented 1 year ago

Released in 9.0.0: https://github.com/voxpelli/node-connect-pg-simple/releases/tag/v9.0.0