首页 > 解决方案 > Nodejs MaxListenersExceededWarning 在 aws lambda 中限制了堆栈跟踪

问题描述

我在带有 API-Gateway 的 AWS lambda 中使用 nodejs 8.10。我收到 MaxListenersExceededWarning。process.setMaxListeners(0);我在 express 应用的 app.js 中尝试过。但仍然存在警告。为了获得更多详细信息,我已将其添加到我的代码中。

process.on('warning', (warning) => {
  console.log("[+] Warning ", JSON.stringify(warning));
  console.log(warning.name); // Print the warning name
  console.log(warning.message); // Print the warning message
  console.log(warning.stack); // Print the stack trace
});

但是堆栈和所有内容的信息非常有限。

{
    "name": "MaxListenersExceededWarning",
    "emitter": {
        "fetching": false,
        "_events": {
            "value": [
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
            ]
        },
        "_eventsCount": 1
    },
    "type": "value",
    "count": 11
}

它没有告诉我具体在哪个地方有错误。另外,这个错误在本地不可用,它只在生产中,所以我不认为有一种方法可以在生产 lambda 中添加 --stack-trace 。

标签: javascriptnode.jsamazon-web-servicesmemory-leaksaws-lambda

解决方案


推荐阅读