Skip to content

Commit 2f4a70a

Browse files
committed
use read only pool - add retry with default pool
Signed-off-by: Amit Prinz Setter <[email protected]>
1 parent c853065 commit 2f4a70a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/util/postgres_client.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function convert_timestamps(where_clause) {
249249
async function _do_query(pg_client, q, transaction_counter) {
250250
query_counter += 1;
251251

252-
dbg.log3("pg_client.options?.host =", pg_client.options?.host, ", q =", q);
252+
dbg.log3("pg_client.options?.host =", pg_client.options?.host, ", retry =", pg_client.retry_with_default_pool, ", q =", q);
253253

254254
const tag = `T${_.padStart(transaction_counter, 8, '0')}|Q${_.padStart(query_counter.toString(), 8, '0')}`;
255255
try {
@@ -268,6 +268,10 @@ async function _do_query(pg_client, q, transaction_counter) {
268268
if (err.routine === 'index_create' && err.code === '42P07') return;
269269
dbg.error(`postgres_client: ${tag}: failed with error:`, err);
270270
await log_query(pg_client, q, tag, 0, /*should_explain*/ false);
271+
if (pg_client.retry_with_default_pool) {
272+
dbg.warn("retrying with default pool. q = ", q);
273+
return _do_query(PostgresClient.instance().get_pool('default'), q, transaction_counter);
274+
}
271275
throw err;
272276
}
273277
}
@@ -1505,7 +1509,8 @@ class PostgresClient extends EventEmitter {
15051509
},
15061510
read_only: {
15071511
instance: null,
1508-
size: config.POSTGRES_DEFAULT_MAX_CLIENTS
1512+
size: config.POSTGRES_DEFAULT_MAX_CLIENTS,
1513+
retry_with_default_pool: true
15091514
}
15101515
};
15111516

@@ -1745,6 +1750,8 @@ class PostgresClient extends EventEmitter {
17451750
};
17461751
}
17471752
pool.instance.on('error', pool.error_listener);
1753+
//propagate retry_with_default_pool into instance so it will be available in _do_query()
1754+
pool.instance.retry_with_default_pool = pool.retry_with_default_pool;
17481755
}
17491756
}
17501757

0 commit comments

Comments
 (0)