Skip to content

server: deploys and scale-downs cut off in-flight requests #814

Open

Description

@bpowers

The Express server has no SIGTERM handler, so when App Engine stops an instance (every deploy and every scale-down) Node exits immediately and any in-flight request is cut off.
It should stop accepting connections, let in-flight requests finish within a short timeout, then exit.

Why it matters

The request that matters is a model save (POST /api/projects/:user/:project).
A save killed mid-request does not silently lose work: the editor shows "Changes not saved" and retries on the next edit.
The bad cases are narrower:

  • Killed after the project row is updated but before the response is sent: the client thinks the save failed, retries with the old version number, gets a 409, and the conflict banner tells the user to reload, which discards their unsaved edits.
  • Killed between writing the new File document and updating the project row: one orphaned File document (the handler's own comment calls this out as the remaining window).
  • The cached preview is invalidated in a setTimeout after the response, so an exit right after a save leaves a stale preview.

Not seen in a user report; inferred from the code.
How long App Engine waits between SIGTERM and killing the process is unverified.

Fix

In src/server/index.ts, keep the http.Server returned by listen() and on SIGTERM/SIGINT call server.close(), then force process.exit after a few seconds.
Optionally await the preview deletion instead of deferring it.

Pointers

  • src/server/index.ts (main), src/server/app.ts (listen() discards the server handle)
  • src/server/api.ts, the save handler and its setTimeout preview deletion
  • docs/tech-debt.md entry 41 (save is not transactional)

Activity

  1. added
    backend
    bug
    on Oct 12, 2026
  2. changed the title [-]server: no SIGTERM/graceful-shutdown handler drops in-flight saves on GAE recycle[/-] [+]server: deploys and scale-downs cut off in-flight requests[/+] on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions