mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
* feat(core): database connection timeout env overwrite support (#6187) * chore: add changeset --------- Co-authored-by: Charles Zhao <charleszhao@silverhand.io>
This commit is contained in:
parent
6289433d8c
commit
bc2a0ac039
4 changed files with 17 additions and 3 deletions
8
.changeset/fifty-apes-arrive.md
Normal file
8
.changeset/fifty-apes-arrive.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
"@logto/shared": patch
|
||||||
|
"@logto/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
add environment variable to override default database connection timeout
|
||||||
|
|
||||||
|
By default, out database connection timeout is set to 5 seconds, which might not be enough for some network conditions. This change allows users to override the default value by setting the `DATABASE_CONNECTION_TIMEOUT` environment variable.
|
|
@ -10,7 +10,8 @@ import {
|
||||||
const createPoolByEnv = async (
|
const createPoolByEnv = async (
|
||||||
databaseDsn: string,
|
databaseDsn: string,
|
||||||
mockDatabaseConnection: boolean,
|
mockDatabaseConnection: boolean,
|
||||||
poolSize?: number
|
poolSize?: number,
|
||||||
|
connectionTimeout?: number
|
||||||
) => {
|
) => {
|
||||||
// Database connection is disabled in unit test environment
|
// Database connection is disabled in unit test environment
|
||||||
if (mockDatabaseConnection) {
|
if (mockDatabaseConnection) {
|
||||||
|
@ -22,6 +23,7 @@ const createPoolByEnv = async (
|
||||||
return createPool(databaseDsn, {
|
return createPool(databaseDsn, {
|
||||||
interceptors: createInterceptorsPreset(),
|
interceptors: createInterceptorsPreset(),
|
||||||
maximumPoolSize: poolSize,
|
maximumPoolSize: poolSize,
|
||||||
|
connectionTimeout,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ export class EnvSet {
|
||||||
static sharedPool = createPoolByEnv(
|
static sharedPool = createPoolByEnv(
|
||||||
this.dbUrl,
|
this.dbUrl,
|
||||||
EnvSet.values.isUnitTest,
|
EnvSet.values.isUnitTest,
|
||||||
this.values.databasePoolSize
|
this.values.databasePoolSize,
|
||||||
|
EnvSet.values.databaseConnectionTimeout
|
||||||
);
|
);
|
||||||
|
|
||||||
#pool: Optional<DatabasePool>;
|
#pool: Optional<DatabasePool>;
|
||||||
|
@ -68,7 +69,8 @@ export class EnvSet {
|
||||||
const pool = await createPoolByEnv(
|
const pool = await createPoolByEnv(
|
||||||
this.databaseUrl,
|
this.databaseUrl,
|
||||||
EnvSet.values.isUnitTest,
|
EnvSet.values.isUnitTest,
|
||||||
EnvSet.values.databasePoolSize
|
EnvSet.values.databasePoolSize,
|
||||||
|
EnvSet.values.databaseConnectionTimeout
|
||||||
);
|
);
|
||||||
|
|
||||||
this.#pool = pool;
|
this.#pool = pool;
|
||||||
|
|
2
packages/shared/src/node/env/GlobalValues.ts
vendored
2
packages/shared/src/node/env/GlobalValues.ts
vendored
|
@ -104,6 +104,8 @@ export default class GlobalValues {
|
||||||
/** Maximum number of clients to keep in a single database pool (i.e. per `Tenant` class). */
|
/** Maximum number of clients to keep in a single database pool (i.e. per `Tenant` class). */
|
||||||
public readonly databasePoolSize = Number(getEnv('DATABASE_POOL_SIZE', '20'));
|
public readonly databasePoolSize = Number(getEnv('DATABASE_POOL_SIZE', '20'));
|
||||||
|
|
||||||
|
public readonly databaseConnectionTimeout = Number(getEnv('DATABASE_CONNECTION_TIMEOUT', '5000'));
|
||||||
|
|
||||||
/** Case insensitive username */
|
/** Case insensitive username */
|
||||||
public readonly isCaseSensitiveUsername = yes(getEnv('CASE_SENSITIVE_USERNAME', 'true'));
|
public readonly isCaseSensitiveUsername = yes(getEnv('CASE_SENSITIVE_USERNAME', 'true'));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue