Skip to content

Send-only client websockets can't detect its peer's request for closure. #899

@vkottler

Description

@vkottler

Per: https://websockets.readthedocs.io/en/stable/_modules/websockets/protocol.html#WebSocketCommonProtocol.send

Canceling send() is discouraged. Instead, you should close the connection with close(). Indeed, there only two situations where send() yields control to the event loop:

The write buffer is full. If you don’t want to wait until enough data is sent, your only alternative is to close the connection.close() will likely time out then abort the TCP connection.
message is an asynchronous iterator. Stopping in the middle of a fragmented message will cause a protocol error. Closing the connection has the same effect.

It seems then that you actually would have to poll recv with wait_for in order to bubble up the connection-closing exception condition. Why is that?

Currently you can just continue successfully awaiting send despite the peer clearly and detectably trying to close the connection. This is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions