Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions postgres/pg-cache/src/lru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export class PgPoolCacheManager {
this.closed = true;
this.clear();
await this.waitForDisposals();
// Re-open the cache so it can accept new entries if the process
// survives the shutdown signal (e.g. during provisioning or restart).
this.closed = false;
}

async waitForDisposals(): Promise<void> {
Expand Down Expand Up @@ -141,9 +144,14 @@ export const close = async (verbose = false): Promise<void> => {
if (closePromise.promise) return closePromise.promise;

closePromise.promise = (async () => {
if (verbose) log.info('Closing pg cache...');
await pgCache.close();
if (verbose) log.success('PG cache disposed.');
try {
if (verbose) log.info('Closing pg cache...');
await pgCache.close();
if (verbose) log.success('PG cache disposed.');
} finally {
// Reset so close() can be called again if the process survives.
closePromise.promise = null;
}
})();

return closePromise.promise;
Expand All @@ -158,4 +166,4 @@ SYS_EVENTS.forEach(event => {

export const teardownPgPools = async (verbose = false): Promise<void> => {
return close(verbose);
};
};