Skip to content

Commit

Permalink
fix: graceful release for dbsync client
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Nov 13, 2024
1 parent 79ebea8 commit a6bdf05
Show file tree
Hide file tree
Showing 97 changed files with 399 additions and 587 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Custom network support
- Option to disable token registery lookups
- Option to disable token registry lookups

### Fixed

- Issue with attempting to release an already-released PostgreSQL client during error handling

## [2.3.1] - 2024-11-04

Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/addresses/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toJSONStream } from '../../../../utils/string-utils.js';
import * as ResponseTypes from '../../../../types/responses/accounts.js';
import * as QueryTypes from '../../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../../utils/validation.js';
import { SQLQuery } from '../../../../sql/index.js';
Expand All @@ -22,7 +22,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -32,7 +32,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -52,7 +52,7 @@ async function route(fastify: FastifyInstance) {
],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return reply.send([]);
Expand All @@ -68,9 +68,7 @@ async function route(fastify: FastifyInstance) {
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toJSONStream } from '../../../../utils/string-utils.js';
import * as ResponseTypes from '../../../../types/responses/accounts.js';
import * as QueryTypes from '../../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../../utils/validation.js';
import { SQLQuery } from '../../../../sql/index.js';
Expand All @@ -22,7 +22,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -32,7 +32,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -52,7 +52,7 @@ async function route(fastify: FastifyInstance) {
],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return reply.send([]);
Expand All @@ -68,9 +68,7 @@ async function route(fastify: FastifyInstance) {
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/addresses/total.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FastifyInstance, FastifyRequest } from 'fastify';
import * as ResponseTypes from '../../../../types/responses/accounts.js';
import * as QueryTypes from '../../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../../utils/validation.js';
import { SQLQuery } from '../../../../sql/index.js';
Expand All @@ -20,7 +20,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -30,7 +30,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -39,7 +39,7 @@ async function route(fastify: FastifyInstance) {
[request.params.stake_address],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

let result_outputs = [];

Expand Down Expand Up @@ -85,9 +85,7 @@ async function route(fastify: FastifyInstance) {

return reply.send(result);
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/delegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toJSONStream } from '../../../utils/string-utils.js';
import * as ResponseTypes from '../../../types/responses/accounts.js';
import * as QueryTypes from '../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../utils/validation.js';
import { SQLQuery } from '../../../sql/index.js';
Expand All @@ -22,7 +22,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -32,7 +32,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -53,7 +53,7 @@ async function route(fastify: FastifyInstance) {
],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return reply.send([]);
Expand All @@ -69,9 +69,7 @@ async function route(fastify: FastifyInstance) {
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toJSONStream } from '../../../utils/string-utils.js';
import * as ResponseTypes from '../../../types/responses/accounts.js';
import * as QueryTypes from '../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../utils/validation.js';
import { SQLQuery } from '../../../sql/index.js';
Expand All @@ -22,7 +22,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -32,7 +32,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -53,7 +53,7 @@ async function route(fastify: FastifyInstance) {
],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return reply.send([]);
Expand All @@ -69,9 +69,7 @@ async function route(fastify: FastifyInstance) {
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
10 changes: 4 additions & 6 deletions src/routes/accounts/stake-address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FastifyInstance, FastifyRequest } from 'fastify';
import * as ResponseTypes from '../../../types/responses/accounts.js';
import * as QueryTypes from '../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../utils/validation.js';
import { SQLQuery } from '../../../sql/index.js';
Expand All @@ -20,7 +20,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -29,17 +29,15 @@ async function route(fastify: FastifyInstance) {
request.params.stake_address,
]);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return handle404(reply);
}

return reply.send(rows[0]);
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/mirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toJSONStream } from '../../../utils/string-utils.js';
import * as ResponseTypes from '../../../types/responses/accounts.js';
import * as QueryTypes from '../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../utils/validation.js';
import { SQLQuery } from '../../../sql/index.js';
Expand All @@ -22,7 +22,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -32,7 +32,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -52,7 +52,7 @@ async function route(fastify: FastifyInstance) {
],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return reply.send([]);
Expand All @@ -68,9 +68,7 @@ async function route(fastify: FastifyInstance) {
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
12 changes: 5 additions & 7 deletions src/routes/accounts/stake-address/registrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toJSONStream } from '../../../utils/string-utils.js';
import * as ResponseTypes from '../../../types/responses/accounts.js';
import * as QueryTypes from '../../../types/queries/accounts.js';
import { getSchemaForEndpoint } from '@blockfrost/openapi';
import { getDbSync } from '../../../utils/database.js';
import { getDbSync, gracefulRelease } from '../../../utils/database.js';
import { handle400Custom, handle404 } from '../../../utils/error-handler.js';
import { validateStakeAddress } from '../../../utils/validation.js';
import { SQLQuery } from '../../../sql/index.js';
Expand All @@ -22,7 +22,7 @@ async function route(fastify: FastifyInstance) {
const isStakeAddressValid = validateStakeAddress(request.params.stake_address);

if (!isStakeAddressValid) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle400Custom(reply, 'Invalid or malformed stake address format.');
}

Expand All @@ -32,7 +32,7 @@ async function route(fastify: FastifyInstance) {
);

if (query404.rows.length === 0) {
clientDbSync.release();
gracefulRelease(clientDbSync);
return handle404(reply);
}

Expand All @@ -52,7 +52,7 @@ async function route(fastify: FastifyInstance) {
],
);

clientDbSync.release();
gracefulRelease(clientDbSync);

if (rows.length === 0) {
return reply.send([]);
Expand All @@ -68,9 +68,7 @@ async function route(fastify: FastifyInstance) {
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
gracefulRelease(clientDbSync);
throw error;
}
},
Expand Down
Loading

0 comments on commit a6bdf05

Please sign in to comment.