【问题标题】:Possible EventEmitter memory leak detected NodeJS - Lambda检测到可能的 EventEmitter 内存泄漏 NodeJS - Lambda
【发布时间】:2021-09-05 13:35:22
【问题描述】:

我正在将一个 graphql 服务器附加到一个 aws lambda 并且我收到此警告正在执行 serverless-offline:

(node:16890) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:16890) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit

我不确定这是什么意思,我快速搜索了一下,似乎 lambda 中的 nodejs 进程消耗了大量内存?不知道是不是我的情况。

我还注意到我收到了很多发送到 graphql 端点的 POST 请求消息,这些消息每秒都在记录:

... A LOT MORE ABOVE

offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v15l004t16fo89ckgze1  Duration: 957.66 ms  Billed Duration: 958 ms

offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v3ge004w16fogcfn6e47  Duration: 1166.56 ms  Billed Duration: 1167 ms

offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v5yj004z16fo8ugr87k4  Duration: 1201.69 ms  Billed Duration: 1202 ms

offline: POST /dev/graphql (λ: graphql)
offline: (λ: graphql) RequestId: ckq75v8gk005216fo1g714h9l  Duration: 966.74 ms  Billed Duration: 967 ms

... A LOT MORE BELOW

我可以理解我的处理程序多次获取 graphql 端点,它可能不应该这样做?

我还注意到操场上的查询非常慢,例如返回“hello world”字符串的简单查询需要 2 秒。但是,当我部署 lambda 时,这个问题并没有发生。使用 API Gateway url 时,速度要快得多。

这是我电脑的问题吗?我什至可以解决这个问题吗?

我有时会遇到内存泄漏问题,导致服务器关闭,抛出此错误:

<--- Last few GCs --->

[15693:0x10291f000]  1554018 ms: Mark-sweep 2014.3 (2058.8) -> 2013.6 (2058.6) MB, 3415.0 / 1.4 ms  (average mu = 0.078, current mu = 0.006) allocation failure GC in old space requested
[15693:0x10291f000]  1557368 ms: Mark-sweep 2014.6 (2058.6) -> 2013.6 (2057.8) MB, 3298.1 / 10.9 ms  (average mu = 0.047, current mu = 0.015) allocation failure scavenge might not succeed


<--- JS stacktrace --->

这是 graphql 处理程序:

const resolvers = {
  Query: {
    hello: () => 'world'
  }
};

const app = express();

const server = new ApolloServer({
  typeDefs,
  resolvers,
});

server.applyMiddleware({ app });

app.get('graphql', graphiql({ endpoint: '/graphql' }));

const handler = serverless(app);

export { handler as graphqlHandler };

和lambda函数:

functions:
  graphql:
    handler: src/graphql.graphqlHandler
    events:
      - http:
          path: graphql
          method: get
          cors: true
      - http:
          path: graphql
          method: post
          cors: true

有人知道发生了什么,或者我应该怎么做才能确定根本错误?

提前致谢!

【问题讨论】:

    标签: node.js amazon-web-services memory-leaks graphql serverless-offline


    【解决方案1】:

    我想我找到了一个临时解决方案。主要问题是我的电脑只剩下 2 GB 的 RAM 空间。因此,graphql 游乐场每 2 秒获取一次我的本地模式。这是操场配置:

    {
      "editor.cursorShape": "line",
      "editor.fontFamily": "'Source Code Pro', 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace",
      "editor.fontSize": 14,
      "editor.reuseHeaders": true,
      "editor.theme": "dark",
      "general.betaUpdates": false,
      "prettier.printWidth": 80,
      "prettier.tabWidth": 2,
      "prettier.useTabs": false,
      "request.credentials": "omit",
      "schema.disableComments": true,
      "schema.polling.enable": false, // Fetch enabled
      "schema.polling.endpointFilter": "*localhost*",
      "schema.polling.interval": 2000, <---- Fetch every 2 seconds
      "tracing.hideTracingResponse": true,
      "queryPlan.hideQueryPlanResponse": true
    }
    

    schema.polling.enable 设置为false 解决了这个问题,但我想我现在每次更改时都必须手动重新获取架构。

    我仍然不知道为什么 node 进程在每次 graphql 提取中都会增加,即使架构没有改变。

    【讨论】:

      猜你喜欢
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 2013-08-01
      相关资源
      最近更新 更多