restatedev / restatedev/sdk-typescript
Add shutdown handling to restate.serve()
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 122
- Forks
- 27
- Avg merge
- 9h 17m
- Merged PRs (30d)
- 8
Description
This is a redux of https://github.com/restatedev/sdk-typescript/issues/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"));
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/restate-sdk/src/node.ts at the standard restate.serve() entrypoint referenced in the issue, and compare it with the createEndpointHandler() workaround. Verify how the HTTP2 server is created and add the requested SIGTERM behavior so server.close() stops new requests while outstanding requests finish.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100