Skip to content

Fix ExpressServer.stop() — does not close keep-alive connections #36

@AdamBHolt

Description

@AdamBHolt

Priority: HIGH
Package: @saga-ed/soa-api-core
Coach ref: ISSUES.md issue #9

ExpressServer.stop() calls http.Server.close() which stops accepting new connections but does not close existing keep-alive connections. This causes graceful shutdown to hang until connections time out or a force-exit timer fires.

Additionally, the underlying serverInstance (http.Server) is private with no getter, so consumers cannot call server.closeAllConnections() (available since Node.js 18.2+) or server.closeIdleConnections() themselves.

Requested changes:

  1. Call this.serverInstance.closeAllConnections() after this.serverInstance.close() in ExpressServer.stop(), or add a configurable drain period before force-closing
  2. Make stop() return a Promise<void> that resolves when the server is fully closed (currently returns void and uses a fire-and-forget callback)
  3. Expose the http.Server instance via a getter (e.g., getServer()) so consumers can manage connection lifecycle if needed

Coach workaround: gqlServer.stop() is raced with a 2-second Promise.race timeout, and the overall force-exit timer is set to 5 seconds. Without this, shutdown hangs for 10+ seconds in development due to browser keep-alive connections from the Apollo Sandbox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions