【问题标题】:at=error code=H12 desc="Request timeout" in node.js.how to deal with it?at=error code=H12 desc="Request timeout" in node.js.如何处理?
【发布时间】:2020-11-10 12:30:35
【问题描述】:

2020-07-21T06:54:58.030920+00:00 heroku[路由器]:

at=error code=H12
> desc="Request timeout"

method=GET path="/Recipies"

host=desolate-beach-26163.herokuapp.com request_id=25f963a1-ce9e-43c6-a054-72c8a7a33ea8 fwd="157.36.134.120" dyno=web.1 连接=1ms 服务=30001ms 状态=503 字节=0 协议=httpsenter code here

【问题讨论】:

    标签: node.js


    【解决方案1】:

    H12 "Request timeout" in Heroku 是由长时间运行的操作引起的。 我不确定您是否使用此路由从数据库中提取数据,但这是common issue when connecting to data sources from node.js on heroku

    首先,检查您的数据库连接字符串,以确保配置没有受到影响。在您的应用程序 (server.js) 的开头,您可以注销数据库 URL:

    console.log("Database_URL", process.env.DATABASE_URL);
    

    点击路线后(在您的情况下为“/Recipies”),检查项目目录中的日志:

    heroku logs --tail
    

    您的连接字符串应该类似于:

    postgres://qi34l...545b4@ec2-3-63-192-23.compute-1.amazonaws.com:5432/aj48e4ewfjow34
    

    如果没有,请检查您的 package.json、Procfile 和 index.js 文件是否有可能覆盖 DATABASE_URL 的内容。

    您可以通过“psql”命令行工具与您的 url 连接来验证连接字符串。它看起来像这样(但用您的连接字符串替换 URL)-

    psql postgres://qi34l...545b4@ec2-3-63-192-23.compute-1.amazonaws.com:5432/aj48e4ewfjow34
    

    如果可以连接,则可能是 postgresql 库的初始化方式存在问题。如果您使用的是最新的“node-postgres”(“pg”),请确保您已将 ssl rejectUnauthorized 设置为 false:

    const { Pool } = require('pg');
    const pool = new Pool({
        connectionString: process.env.DATABASE_URL,
        ssl: { rejectUnauthorized: false }
    });
    

    【讨论】:

    • 难道没有办法增加 Heroku 应用的超时时间吗?
    猜你喜欢
    • 1970-01-01
    • 2018-04-09
    • 2020-12-04
    • 1970-01-01
    • 2015-04-01
    • 2015-03-01
    • 2013-03-30
    • 2019-07-04
    相关资源
    最近更新 更多