Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get error Error while initializing #6187

Open
peteryang1756 opened this issue Jul 5, 2024 · 6 comments
Open

Get error Error while initializing #6187

peteryang1756 opened this issue Jul 5, 2024 · 6 comments
Assignees
Labels
pending-verification Something is still under investigation stale

Comments

@peteryang1756
Copy link

I try to delopy logto on Render and get this error,How to fix it

    (node:17) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
index    error Error while initializing app:
index    error Error: timeout expired
    at Timeout._onTimeout (/etc/logto/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:106:28)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7)
@peteryang1756 peteryang1756 added the bug Something isn't working label Jul 5, 2024
@charIeszhao
Copy link
Member

It seems you have issues connecting to the database. Can you share your config?

@peteryang1756
Copy link
Author

peteryang1756 commented Jul 5, 2024

It seems you have issues connecting to the database. Can you share your config?

This is my db config
DB_URL=postgres://postgres.woefiqksuduiihlynziwdydegh:[email protected]:6543/postgres

@filipdjokic
Copy link

We've also encountered the same timeout error during app initialization with v1.16.0, v1.17.0 and v1.18.0.

After some investigation, we managed to resolve it by adding the connectionTimeout configuration parameter to the createPoolByEnv function:

const createPoolByEnv = async (
  databaseDsn: string,
  mockDatabaseConnection: boolean,
  poolSize?: number,
  connectionTimeout?: number
) => {
  // Database connection is disabled in unit test environment
  if (mockDatabaseConnection) {
    return createMockPool({ query: async () => createMockQueryResult([]) });
  }

  assert(parseDsn(databaseDsn).databaseName, new Error('Database name is required'));

  return createPool(databaseDsn, {
    interceptors: createInterceptorsPreset(),
    maximumPoolSize: poolSize,
    connectionTimeout: connectionTimeout,
  });
};

Additionally, we've added an environment variable named DATABASE_CONNECTION_TIMEOUT, which if unset will have the default value of 10_000 (in our case setting it to 30_000 resolved the issue).
This way, the environment variable will remain optional, allowing people to adjust this setting if needed.

Is this something you would consider including in the next release? Happy to contribute and help with the implementation.

@charIeszhao
Copy link
Member

We've also encountered the same timeout error during app initialization with v1.16.0, v1.17.0 and v1.18.0.

After some investigation, we managed to resolve it by adding the connectionTimeout configuration parameter to the createPoolByEnv function:

const createPoolByEnv = async (
  databaseDsn: string,
  mockDatabaseConnection: boolean,
  poolSize?: number,
  connectionTimeout?: number
) => {
  // Database connection is disabled in unit test environment
  if (mockDatabaseConnection) {
    return createMockPool({ query: async () => createMockQueryResult([]) });
  }

  assert(parseDsn(databaseDsn).databaseName, new Error('Database name is required'));

  return createPool(databaseDsn, {
    interceptors: createInterceptorsPreset(),
    maximumPoolSize: poolSize,
    connectionTimeout: connectionTimeout,
  });
};

Additionally, we've added an environment variable named DATABASE_CONNECTION_TIMEOUT, which if unset will have the default value of 10_000 (in our case setting it to 30_000 resolved the issue). This way, the environment variable will remain optional, allowing people to adjust this setting if needed.

Is this something you would consider including in the next release? Happy to contribute and help with the implementation.

Thanks for the information. Sorry for not being able to reply earlier.
A contribution PR is always welcomed. Follow the contribution guidelines and let us know if you need any help.

@charIeszhao charIeszhao self-assigned this Oct 10, 2024
@charIeszhao charIeszhao added pending-verification Something is still under investigation and removed bug Something isn't working labels Oct 10, 2024
@luis815
Copy link
Contributor

luis815 commented Oct 14, 2024

If it's OK, I essentially implemented the change mentioned above. Raised PR #6674

charIeszhao added a commit that referenced this issue Oct 18, 2024
…#6674)

* feat(core): database connection timeout env overwrite support (#6187)

* chore: add changeset

---------

Co-authored-by: Charles Zhao <[email protected]>
Copy link

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-verification Something is still under investigation stale
Development

No branches or pull requests

4 participants