Skip to content

Commit 52f5457

Browse files
authored
Merge pull request #787 from constructive-io/devin/1772793999-fix-pg-cache-reopen
fix(pg-cache): allow cache to reopen after close for process survival
2 parents b70ee76 + cea2f6b commit 52f5457

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

postgres/pg-cache/src/lru.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ export class PgPoolCacheManager {
105105
this.closed = true;
106106
this.clear();
107107
await this.waitForDisposals();
108+
// Re-open the cache so it can accept new entries if the process
109+
// survives the shutdown signal (e.g. during provisioning or restart).
110+
this.closed = false;
108111
}
109112

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

143146
closePromise.promise = (async () => {
144-
if (verbose) log.info('Closing pg cache...');
145-
await pgCache.close();
146-
if (verbose) log.success('PG cache disposed.');
147+
try {
148+
if (verbose) log.info('Closing pg cache...');
149+
await pgCache.close();
150+
if (verbose) log.success('PG cache disposed.');
151+
} finally {
152+
// Reset so close() can be called again if the process survives.
153+
closePromise.promise = null;
154+
}
147155
})();
148156

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

159167
export const teardownPgPools = async (verbose = false): Promise<void> => {
160168
return close(verbose);
161-
};
169+
};

0 commit comments

Comments
 (0)