Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak with hono, @hono/node-server, @hono/graphql-server #171

Closed
kyscott18 opened this issue May 23, 2024 · 0 comments · Fixed by #172
Closed

Memory leak with hono, @hono/node-server, @hono/graphql-server #171

kyscott18 opened this issue May 23, 2024 · 0 comments · Fixed by #172

Comments

@kyscott18
Copy link

It seems like there is a memory leak when using hono, @hono/node-server, and @hono/graphql-server together.

Minimal reproduction mostly from the example in @hono/graphql-server:

import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { graphqlServer } from "@hono/graphql-server";
import { buildSchema } from "graphql";

setInterval(() => {
  const before = process.memoryUsage().heapUsed / 1024 / 1024;
  global.gc?.();
  const after = process.memoryUsage().heapUsed / 1024 / 1024;
  console.log({ before: before.toFixed(2), after: after.toFixed(2) });
}, 1_000);

export const app = new Hono();

const schema = buildSchema(`
type Query {
  hello: String
}
`);

const rootResolver = (ctx) => {
  return {
    hello: () => "Hello Hono!",
  };
};

app.use(
  "/graphql",
  graphqlServer({
    schema,
    rootResolver,
  })
);

serve(app);

Result of running the server and then sending requests with autocannon after a few seconds:

autocannon -c 100 -d 10 -m POST -H "Content-Type: application/json" -b '{"query":"{ hello }"}' http://localhost:3000/graphql
(base) kylescott@Kyles-MacBook-Pro-2 hono-node-repro % node --expose-gc index.js
{ before: '8.86', after: '6.72' }
{ before: '6.83', after: '6.75' }
{ before: '6.77', after: '6.75' }
{ before: '6.77', after: '6.75' }
{ before: '6.82', after: '6.76' }
{ before: '6.78', after: '6.76' }
{ before: '6.83', after: '6.77' }
{ before: '55.64', after: '37.63' }
{ before: '153.87', after: '97.79' }
{ before: '205.73', after: '152.70' }
{ before: '262.65', after: '208.79' }
{ before: '310.95', after: '259.03' }
{ before: '355.99', after: '308.32' }
{ before: '400.77', after: '354.94' }
{ before: '444.92', after: '398.86' }
{ before: '489.06', after: '443.80' }
{ before: '523.01', after: '484.06' }
{ before: '565.09', after: '523.40' }

https://github.com/kyscott18/hono-node-mem-leak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant