Can ngrok forward client cancellation to the backend?
0 reputation · 04 Feb 2023, 22:28 UTC
0 reputation · 04 Feb 2023, 22:28 UTC
Determine whether ngrok propagates a client‑initiated HTTP abort or WebSocket close frame to the upstream service, and identify the configuration knobs that control this behavior.
ngrok’s HTTP API exposes a request timeout setting, but the documentation does not mention how client‑side cancellations are handled. The control API can terminate tunnels, yet it does not signal in‑flight request cancellation. Local server settings such as proxy_read_timeout and proxy_write_timeout influence wait times for data but have no documented effect on client‑side disconnects. Version differences and plan‑based limits may also alter the observed behavior.
32775 reputation · 05 Feb 2023, 04:10 UTC
Yes. ngrok propagates client-initiated cancellation to the upstream service, but it does so by closing the backend connection rather than sending a distinct HTTP abort message. For WebSocket tunnels, close frames are forwarded with their code and reason intact.
ngrok operates as a reverse proxy. When a client disconnects mid-request, ngrok detects the TCP connection close and tears down the corresponding upstream connection to your backend. The backend does not receive a special HTTP "Abort" signal; instead, it observes a connection reset or an unexpected EOF on its socket. This is the standard cancellation mechanism for HTTP traffic through a proxy.
For WebSocket endpoints, ngrok forwards the WebSocket close frame from the client to the backend server. The close code and reason string are preserved as part of the protocol exchange. This allows the backend to distinguish a normal closure from an abnormal disconnect, provided the client itself sends a well-formed close frame.
There is no ngrok configuration option that enables or disables cancellation propagation; the behavior is inherent to the proxy architecture and applies by default. Settings such as the agent's request timeout or WebSocket idle limits control how long ngrok waits for backend activity, but they do not toggle abort forwarding. The control API can terminate an entire tunnel or session, which closes all in-flight connections, but that is an administrative action distinct from relaying an individual client cancellation.
Confirmed by proxy architecture: HTTP cancellation manifests as an upstream TCP close. Likely but version-dependent: WebSocket close-frame forwarding preserves code and reason across all agent versions and plans. Because no live version was tested here, verify WebSocket behavior against your specific ngrok agent version. If your backend is not observing the close, share the protocol and agent version in use, since version-specific handling may affect the outcome.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.