Skip to content

Commit

Permalink
fix: use an independent sql connection for mempool stats (#2217)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Feb 6, 2025
1 parent c80d9df commit f8137e4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/datastore/pg-write-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2034,8 +2034,13 @@ export class PgWriteStore extends PgStore {
this._debounceMempoolStat.debounce = setTimeout(async () => {
this._debounceMempoolStat.running = true;
this._debounceMempoolStat.triggeredAt = null;
const sql = await connectPostgres({
usageName: `mempool-debounce`,
connectionArgs: getConnectionArgs(PgServer.primary),
connectionConfig: getConnectionConfig(PgServer.primary),
});
try {
const mempoolStats = await this.sqlTransaction(async sql => {
const mempoolStats = await sql.begin(async sql => {
return await this.getMempoolStatsInternal({ sql });
});
this.eventEmitter.emit('mempoolStatsUpdate', mempoolStats);
Expand All @@ -2052,6 +2057,7 @@ export class PgWriteStore extends PgStore {
logger.error(e, `failed to run mempool stats update`);
}
} finally {
await sql.end();
this._debounceMempoolStat.running = false;
this._debounceMempoolStat.debounce = null;
if (this._debounceMempoolStat.triggeredAt != null) {
Expand Down

0 comments on commit f8137e4

Please sign in to comment.