Skip to content

Feature request: raise an exception on send() if client is already disconnected #650

@aldem

Description

@aldem

Currently, the response is simply "swallowed" if the client is disconnected in the meantime. It would be nice to let the app be aware of such cases and raise an exception in the send() method: https://asgi.readthedocs.io/en/latest/specs/www.html#disconnected-client-send-exception.

Granian logs a message [INFO] ASGI transport error: SendError { .. } on every failed send, and the log becomes cluttered, while we don't even know which request (and client/ip) is causing this. This is especially annoying when the response has lots of chunks, i.e. send() is called thousands of times.

Use case: both malicious and erroneous disconnections can occur, and this hurts the app if requests are either expensive or take some time to finish. If the app is aware, it will have a chance to at least log such issues, allowing for subsequent analysis to take appropriate action, or to stop sending a long response body if the client suddenly disconnects.

PS: Ideally, of course, it would be nice to somehow signal the app that the client is disconnected, giving it a chance to cancel an active request. Unfortunately, this is beyond the current specifications...

Metadata

Metadata

Assignees

No one assigned

    Labels

    asgiIssue related to ASGI protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions