-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
This is a redux of #11
In the standard entrypoint restate.serve() (code), consider handling SIGTERM by calling server.close(), to stop taking new requests and to allow outstanding requests to complete before the process exits. Relying on tini to kill your process could interrupt an in-flight request, and ignoring the signal altogether (by running as PID 1) makes pods appear to hang during maintenance operations.
Having a built-in handler would make the SDK behave more consistently across environments.
A workaround is to use restate.createEndpointHandler() to take control of the server:
// Create HTTP2 server with manual lifecycle control for graceful shutdown
const handler = restate.createEndpointHandler({ services: [greeter] });
const server = http2.createServer(handler);
const PORT = 9080;
server.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
// Graceful shutdown on SIGTERM (kubelet) and SIGINT (Ctrl+C)
const shutdown = (signal: string) => {
console.log(`Received ${signal}, shutting down gracefully...`);
server.close(() => {
console.log(`Server closed, exiting.`);
process.exit(0);
});
};
process.on("SIGTERM", () => shutdown("SIGTERM"));
process.on("SIGINT", () => shutdown("SIGINT"));Metadata
Metadata
Assignees
Labels
No labels