Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michael-schaefer-eu opened this issue Jun 7, 2018 · 3 comments

Comments

@michael-schaefer-eu
Copy link

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.

@garraeth
Copy link

Could it be because the server is not returning anything? When that happened to me, I found that receive_fragment() (base.php) was the culprit. After line 143 in base.php, I added:

      If ( $data == "" ) {
        if ( $this->huge_payload ) {
          // sp we need to retreive the whole payload
          $payload            = $this->huge_payload;
          $this->huge_payload = null;
          return $payload;
        }
        return '';
      }

@michael-schaefer-eu
Copy link
Author

Hey @garraeth, thank you for your input, but I'm not working on the project that used this websocket anymore, so I can't test that.

@sirn-se
Copy link
Contributor

sirn-se commented May 31, 2020

Fixed in v1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants