grpc-node icon indicating copy to clipboard operation
grpc-node copied to clipboard

idle session timeout / cleanup

Open travisghansen opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I recently discovered a bug in a little proxy server (that sits in 'front' of my nodejs server) I wrote where instead of re-using the same connection for each request a new session was being created per-request. After digging around a bit I saw 10s of thousands of sessions being held that were all certainly idle after 1 request. I have since fixed the bug in the proxy (https://github.com/democratic-csi/csi-grpc-proxy/commit/70ba96767462a72b91bd986309942d6cfb72166d) but was wondering if there's some way I can put an idle timeout or similar on the server-side as well to cleanup such issues? Some clients I may not have control of that may behave 'badly' which makes a server-side solution appealing in those scenarios.

Describe the solution you'd like

Would like to set a parameter on the server that automatically closes idle sessions after a certain amount of time.

Describe alternatives you've considered

It may be feasible to put a setInterval and iterate server.sessions and perhaps see last activity per-session there and then invoke a method on the session to close it down?

travisghansen avatar Apr 05 '22 21:04 travisghansen

Since @grpc/grpc-js version 1.8.0, servers support the options grpc.max_connection_age_ms and grpc.max_connection_age_grace_ms to close connections after they have been open for a certain period of time. This does not only apply to idle connections, but clients that are still using their connections can just reestablish them.

murgatroid99 avatar Dec 14 '23 22:12 murgatroid99

As of @grpc/grpc-js version 1.10.2, servers can now drop idle connections. That behavior is configured with the grpc.max_connection_idle_ms options.

murgatroid99 avatar Apr 01 '24 23:04 murgatroid99