restatedev / restatedev/sdk-typescript

Add shutdown handling to restate.serve()

Open
#628 0 comments 3 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.