Skip to content

Conversation

@usualoma
Copy link
Member

Normally, this setting is not required, but for environments where GC execution is expected to be delayed, an option has been added to explicitly trigger GC every N requests.

app

import { Hono } from 'hono'
import { serve } from '@hono/node-server' 

const app = new Hono()

app.get('/', (c) => c.text('OK'))

serve(
  {
    fetch: app.fetch,
    requestsPerForcedGC: 1000, // Explicitly trigger garbage collection every 1000 requests.
  },
  (info) => {
    console.log(`Server is running on http://localhost:${info.port}`)
  }
)

runner

$ node --expose-gc dist/index.js

@usualoma
Copy link
Member Author

Hi @yusukebe

There's no guarantee that issue #269 will be resolved, but based on our investigation so far, I believe memory is being freed when global.gc() is explicitly called. How about we try implementing this change?

@yusukebe
Copy link
Member

I've been thinking about this for a long time. "Clearing something every certain number of requests" is making me think nostalgically of MaxRequestsPerChild in Apache.

It may be a practical solution. But I wonder if this is a good way for "Node.js"? I checked, and Express doesn't have a function like that. So I am not sure this method is suitable for the Node.js Adapter. It's better to wait; we've got more reports about memory leaks.

@usualoma
Copy link
Member Author

usualoma commented Nov 1, 2025

Hi @yusukebe, thank you for the review.
Yes, I don't think it's an essential fix.

Ideally, we'd eliminate the memory increase caused by AbortSignal...

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 this pull request may close these issues.

2 participants