proxy_ignore_client_abort: need conditional behavior based on response status code
0 reputation · 09 Feb 2020, 20:58 UTC
0 reputation · 09 Feb 2020, 20:58 UTC
The goal is to have nginx continue fetching from an upstream server only when the client aborts and the upstream response is expected to be successful (e.g., 2xx status), while aborting the upstream connection for other cases such as error responses.
Currently the directive offers only a global on/off switch; there is no way to tie its behavior to response attributes like status code, content length, or request headers.
This limitation forces administrators to choose between wasting upstream resources on aborts or losing potential side‑effects from long‑running processes that might still be useful even after the client disconnects.
No. In standard Nginx distributions, proxy_ignore_client_abort is a binary switch (on or off). It cannot be conditioned on the upstream response status code, content length, or any other runtime attribute of the response.
The limitation exists because proxy_ignore_client_abort determines how Nginx handles the connection before the upstream server has sent the response headers. If the directive is off and the client disconnects, Nginx immediately closes the connection to the upstream server to save resources. Because the status code is only known after the upstream begins responding, Nginx cannot use that code to decide whether to ignore the abort in real-time.
Since there is no native conditional directive, you can approximate this behavior using the following methods, depending on your build:
header_filter_by_lua_block to inspect the status code. While Lua cannot retroactively change the proxy_ignore_client_abort setting for a request already in progress, you can implement complex logic to manage how the response is buffered or passed back to the client.202 Accepted status immediately. This decouples the HTTP connection lifecycle from the process execution.proxy_intercept_errors on; allows Nginx to serve a custom error_page for non-2xx responses. While this changes what the client sees, it does not prevent the upstream connection from being closed if the client aborts and proxy_ignore_client_abort is off.To verify current behavior in your environment, you can use a simple upstream script that logs when it receives a disconnect signal:
proxy_ignore_client_abort off;proxy_ignore_client_abort on; to confirm the process continues to completion.Note on Patches: While various community discussions exist regarding adding status-based abort logic, there is no widely adopted or official patch in the mainline Nginx distribution that implements a proxy_ignore_client_abort_status directive.
To provide a more specific Lua implementation if required, please confirm if you are using a standard Nginx build or an OpenResty distribution.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.