簡體   English   中英

Sequelize 在連接到 heroku postgres 數據庫時卡住了

[英]Sequelize gets stuck connecting to heroku postgres database

SO上有很多這樣的問題,但沒有一個真的有同樣的問題。

我正在嘗試使用 sequelize 連接到 Postgres 數據庫,並在本地與 heroku 上托管的數據庫一起使用。 幾天前它也確實有效,但現在沒有了,並且查看差異在應用程序連接到數據庫的方式上沒有任何變化。

當我部署應用程序時,它在嘗試連接到數據庫時卡住了,直到網絡工作者因為應用程序沒有綁定到端口而引發超時。 這使得調試變得困難,因為我沒有要處理的錯誤。

  async connect(): Promise<void> {
    const dbUrl = process.env.DATABASE_URL as string

    if (!dbUrl) {
      throw new Error('Cannot connect to database, url not set!')
    }

    logger.info(`connecting to database ${dbUrl.replace(/:(\w+)@/, ':***@')}`)

    this.sequelize = new Sequelize(dbUrl, {
      dialect: 'postgres',
      protocol: 'postgres',
      logging: (sql, timing) => {
        logger.debug(`Executed SQL query '${sql}' in ${timing} ms`)
      },
      dialectOptions: {
        decimalNumbers: true,
        ssl: true
      }
    })
    
    // it gets stuck here
    await this.sequelize.authenticate({
      logging: (sql, timing) => {
        logger.debug(`authentication ${sql}, ${timing}`)
      }
    })
    logger.info('Database connection successful')

    logger.info('initializing models...')
    await this.initializeModels(this.sequelize)
    logger.info('synching database...')
    await this.sequelize.sync({
      alter: true,
      logging: (sql, timing) => {
        logger.debug(`Executed SQL query '${sql}' in ${timing} ms`)
      }
    })
  }

這里的日志輸出:

ct 23 02:59:34 staging-monk-backend heroku/web.1 State changed from crashed to starting
Oct 23 02:59:40 staging-monk-backend heroku/web.1 Starting process with command `npm start`
Oct 23 02:59:43 staging-monk-backend app/web.1
Oct 23 02:59:43 staging-monk-backend app/web.1 > 8bit-bot-backend@1.0.0 start /app
Oct 23 02:59:43 staging-monk-backend app/web.1 > node build/main.js
Oct 23 02:59:43 staging-monk-backend app/web.1
Oct 23 02:59:44 staging-monk-backend app/web.1 2020-10-23T09:59:44.371Z [info] : NODE_ENV is production 
Oct 23 02:59:44 staging-monk-backend app/web.1 2020-10-23T09:59:44.375Z [info] : debug mode is off  
Oct 23 02:59:44 staging-monk-backend app/web.1 2020-10-23T09:59:44.375Z [info] : connecting to database postgres://rlbditxvnovvvq:***@ec2-54-246-87-132.eu-west-1.compute.amazonaws.com:5432/dd1v94insrdacc 
Oct 23 02:59:45 staging-monk-backend app/api Build succeeded
Oct 23 03:00:40 staging-monk-backend heroku/web.1 Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Oct 23 03:00:40 staging-monk-backend heroku/web.1 Stopping process with SIGKILL
Oct 23 03:00:41 staging-monk-backend heroku/web.1 Process exited with status 137
Oct 23 03:00:41 staging-monk-backend heroku/web.1 State changed from starting to crashed

Procfile:

web:npm start

版本

  • pg :7.5.0
  • sequelize :6.3.5

這個問題為我指明了正確的方向。 問題是pg包版本,升級到 8.4.1 后一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM