Skip to content

Commit c02cae1

Browse files
Merge pull request #317 from blockfrost/chore/session-timeout
chore: configurable idle_session_timeout
2 parents a999555 + f715684 commit c02cae1

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [6.3.4] - 2026-03-17
11+
12+
### Added
13+
14+
- Configurable `idle_session_timeout` for dbsync connections. Set via `dbSync.idleSessionTimeoutMs` in config or `BLOCKFROST_CONFIG_DBSYNC_IDLE_SESSION_TIMEOUT_MS` env var (value in milliseconds). Cleans up zombie connections from restarted PM2 instances. Disabled by default
15+
16+
### Fixed
17+
18+
- Fixed connection leak in `/governance/proposals/:gov_action_id/metadata` where the DB connection was not released on validation failure
19+
1020
## [6.3.3] - 2026-03-13
1121

1222
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockfrost-backend-ryo",
3-
"version": "6.3.3",
3+
"version": "6.3.4",
44
"description": "",
55
"keywords": [],
66
"license": "Apache-2.0",

src/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ const start = (options = {}): FastifyInstance => {
118118
application_name: config.dbSync.applicationName,
119119
statement_timeout: config.dbSync.statementTimeout,
120120
connectionTimeoutMillis: config.dbSync.connectionTimeoutMs,
121+
...(config.dbSync.idleSessionTimeoutMs !== undefined && {
122+
options: `-c idle_session_timeout=${config.dbSync.idleSessionTimeoutMs}`,
123+
}),
121124
});
122125

123126
// proxies

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ export const loadConfig = () => {
8383
: config.has('dbSync.connectionTimeoutMs')
8484
? config.get<number>('dbSync.connectionTimeoutMs')
8585
: undefined;
86+
const databaseSyncIdleSessionTimeoutMs = process.env
87+
.BLOCKFROST_CONFIG_DBSYNC_IDLE_SESSION_TIMEOUT_MS
88+
? Number(process.env.BLOCKFROST_CONFIG_DBSYNC_IDLE_SESSION_TIMEOUT_MS)
89+
: config.has('dbSync.idleSessionTimeoutMs')
90+
? config.get<number>('dbSync.idleSessionTimeoutMs')
91+
: undefined;
8692
const ssl = config.has('dbSync.ssl') ? { rejectUnauthorized: false } : false;
8793
const databaseSyncApplicationName =
8894
process.env.BLOCKFROST_CONFIG_APPLICATION_NAME ??
@@ -168,6 +174,7 @@ export const loadConfig = () => {
168174
maxConnections: databaseSyncMaxConnections,
169175
statementTimeout: databaseSyncStatementTimeout,
170176
connectionTimeoutMs: databaseSyncConnectionTimeoutMs,
177+
idleSessionTimeoutMs: databaseSyncIdleSessionTimeoutMs,
171178
ssl,
172179
applicationName: databaseSyncApplicationName,
173180
},

src/routes/governance/proposals/gov-action-id/metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ async function route(fastify: FastifyInstance) {
1313
method: 'GET',
1414
schema: getSchemaForEndpoint('/governance/proposals/{gov_action_id}/metadata'),
1515
handler: async (request: FastifyRequest<QueryTypes.RequestParametersGovAction>, reply) => {
16-
const clientDbSync = await getDbSync(fastify);
17-
1816
let parsedGovAction;
1917

2018
try {
@@ -23,6 +21,8 @@ async function route(fastify: FastifyInstance) {
2321
return handle400Custom(reply, 'Invalid or malformed gov action id.');
2422
}
2523

24+
const clientDbSync = await getDbSync(fastify);
25+
2626
try {
2727
const { rows } = await clientDbSync.query<QueryTypes.ProposalsProposalMetadata>(
2828
SQLQuery.get('governance_proposals_proposal_metadata_v2'),

0 commit comments

Comments
 (0)