1

I am attaching a graphql server to a aws lambda and I getting this warning executing 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

I am not sure what this means, I did a quick search and It seems that the nodejs process inside the lambda is consuming a lot of memory? I do not know if this is my case.

I also notices that I am getting a lot of messages of POST requests to the graphql endpoint, which keep logging every second:

... 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

I can understand that my handler is fetching the graphql endpoint a lot of times, and It maybe It shouldn't be doing that?

I also noticed that the queries in the playground are extremely slow, like 2 seconds for a simple query that returns a 'hello world' string. However this problem is not happening when I deploy the lambda. When using the API Gateway url it is so much faster.

Is this a problem with my computer? Can I even fix this?

I faced a memory leak problems sometimes which shut down the server, throwing this error:

<--- 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 --->

This this the graphql handler:

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 };

And lambda function:

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

Has someone an idea of what is going on, or what should I do to determine the root error?

Thanks in advance!

1 Answers1

0

I think I found a temporary solution. The main problem is that my computer has only like 2 GB left of RAM space. So the graphql playground was fetching my local schema every 2 seconds. Here is the playground config:

{
  "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
}

Setting the schema.polling.enable to false solved the problem, but I suppose I have now to refetch manually the schema every time it changes.

I still don't know why is the node process increasing in every graphql fetch, even if the schema doesn't change.