AWS Lambda在50毫秒内随机获得操作超时

时间:2020-11-09 03:43:20

标签: node.js aws-lambda sequelize.js

我正在配置的Lambda上运行带有sequelize的nodejs:

    pool: {
        max: 5,
        min: 0,
        acquire: 20000,
        idle: 10000
    }

Env:

Node: 10.x
Sequelize: 6.3.5
ERROR   Unhandled Promise Rejection 
{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "SequelizeConnectionAcquireTimeoutError: Operation timeout",
    "reason": {
        "errorType": "SequelizeConnectionAcquireTimeoutError",
        "errorMessage": "Operation timeout",
        "name": "SequelizeConnectionAcquireTimeoutError",
        "parent": {
            "errorType": "Error",
            "errorMessage": "Operation timeout",
            "stack": [
                "Error: Operation timeout",
                "    at Timeout._timeout.setTimeout (/var/task/node_modules/sequelize-pool/lib/Deferred.js:17:25)",
                "    at ontimeout (timers.js:436:11)",
                "    at tryOnTimeout (timers.js:300:5)",
                "    at listOnTimeout (timers.js:263:5)",
                "    at Timer.processTimers (timers.js:223:10)"
            ]
        },
        "original": {
            "errorType": "Error",
            "errorMessage": "Operation timeout",
            "stack": [
                "Error: Operation timeout",
                "    at Timeout._timeout.setTimeout (/var/task/node_modules/sequelize-pool/lib/Deferred.js:17:25)",
                "    at ontimeout (timers.js:436:11)",
                "    at tryOnTimeout (timers.js:300:5)",
                "    at listOnTimeout (timers.js:263:5)",
                "    at Timer.processTimers (timers.js:223:10)"
            ]
        },
        "stack": [
            "SequelizeConnectionAcquireTimeoutError: Operation timeout",
            "    at ConnectionManager.getConnection (/var/task/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:288:48)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: SequelizeConnectionAcquireTimeoutError: Operation timeout",
        "    at process.on (/var/runtime/index.js:37:15)",
        "    at process.emit (events.js:198:13)",
        "    at process.EventEmitter.emit (domain.js:448:20)",
        "    at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)",
        "    at process._tickCallback (internal/process/next_tick.js:69:34)"
    ]
}

我还有另一个Lambda函数,它们具有完全相同的设置(但使用节点12而不是节点10),每小时处理更多的请求,但每个请求执行的次数更少,并且运行良好。

问题在于此Lambda函数仅偶尔超时,并且仅在10-50ms后才超时 我不知道这是怎么发生的。代码中未使用任何事务。任何帮助都感激不尽。谢谢

1 个答案:

答案 0 :(得分:0)

致任何遇到此错误的人。就我而言,建立与数据库的连接后,任何未处理的错误都不会记录到堆栈跟踪中,并且会返回此错误。

我认为这是由Nodejs试图关闭连接引起的。