Admin API AbortSignal support for request cancellation in Ghost
0 reputation · 25 Apr 2023, 18:08 UTC
0 reputation · 25 Apr 2023, 18:08 UTC
Ghost’s HTTP server treats each request as cancelable when the underlying socket emits a 'close' or 'end' event, allowing middleware to abort processing early. The Ghost CLI’s ghost stop command initiates a graceful shutdown that respects the server.shutdownTimeout setting (default 5000 ms) introduced in Ghost 5.0. However, the Admin API does not yet honor the AbortSignal sent by fetch‑based clients, so client‑side cancellation is not propagated to the server side.
The goal is to clarify whether the Admin API should be extended to respect AbortSignal for request cancellation, considering the existing socket‑based cancellation mechanism and the impact of reverse proxies that may delay socket close events.
What is the expected behavior for Admin API endpoints when a client aborts a request? Is there a planned timeline or version for adding AbortSignal support? Are there any recommended workarounds for clients that need reliable cancellation until native support is added?
Ghost’s HTTP stack listens to the underlying TCP socket. When the socket emits close or end, the request is considered cancelled and middleware can stop processing. The Admin API routes, however, do not read an AbortSignal that a fetch‑based client might attach. Consequently, the request body and any database work continue on the server until the socket is closed or the handler finishes.
As of the latest 5.x releases, there is no official roadmap entry or scheduled version that adds native AbortSignal propagation to the Admin API. The Ghost core team has documented the socket‑based cancellation model but has not announced a migration to signal‑based cancellation.
proxy_read_timeout (Nginx) or timeout (HAProxy) so that the connection is torn down quickly when the client aborts. This forces the socket close event to reach Ghost faster.ghost stop), the server.shutdownTimeout setting will cause pending requests to finish or be aborted after the timeout. Clients should avoid aborting during shutdown if they rely on a response.If your application requires the server to abort processing as soon as the client disconnects, you can:
req.socket for close and manually abort any async operations.p-cancelable or AbortController on the server side, passing a signal that you trigger when the socket closes.If you are running Ghost behind a specific reverse proxy and already have aggressive close settings, let us know the timeout values. Depending on those settings, the socket‑based cancellation may already be effectively instant, making the additional workarounds optional.
// Example: abort async work on socket close
req.socket.on('close', () => {
// signal cancellation to any in‑flight promises
cancelToken();
});
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.