Skip to content

Client doesn't know when the server closed the stream and throws an exception #57

@michael-schaefer-eu

Description

@michael-schaefer-eu

It took me a while to understand this, so I will leave this as a note for others:

My usecase: I use this library to interact with the Chrome DevTools. When I close a target (like a tab), Chrome closes the websocket stream automatically. When I try to close the websocket stream via the close() function, the client will throw an exception. I would expect that the close() function ignores an already closed stream, but instead it will try to write a 'closing frame' to it and fail.

The WebSocket\Client won't notice when the server closes the websocket.

Instead it will throw a WebSocket\ConnectionException with a message like

Empty read; connection dead? Stream state: {"timed_out":false,"blocked":true,"eof":true,"stream_type":"tcp_socket/ssl","mode":"r+","unread_bytes":0,"seekable":false}

The important part is eof:true which means that the stream was closed.

Example: Start a websocket server and connect to it. While the client is connected, kill the server and inspect the client. Its member $is_connected is still true. Try to perform any action (ie. write or close) and it will throw the exception.

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