Skip to content

Endless loop when writing to disconnected socket #11

Description

@andreme

In Buffer->handleWrite() the result of fwrite is compared to false to check for errors.
In my case it returns 0 (and fills lastError with fwrite(): send of 49 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.).

The check for (0 === $sent && feof($this->stream)) fails as well because feof($this->stream) returns false.
Removing && feof($this->stream) fixes the problem.

I use the socket server and socket client. When I kill the server process and the client tries to write something, it loops forever with 100% cpu.

For further reference: http://php.net/manual/en/function.fwrite.php#96951

Activity

  1. steverhoades commented on Nov 4, 2014

    @steverhoades
    Contributor

    @andreme sounds like you have a way to reproduce this, do you mind providing a gist? That would help in expediting a fix.

  2. andreme commented on Nov 6, 2014

    @andreme
    Author

    @steverhoades
    It seems to be a windows only issue (Windows 7).
    I tested this on debian and there is no problem.

    Run the server.php, run client.php in another terminal, kill the server with ctrl-c.
    The client should hang after the 10 seconds are over.

    https://gist.github.com/andreme/d0d6408ca9eed42080f0

  3. clue commented on Nov 6, 2014

    @clue
    Member

    Thanks for providing the gist @andreme!

    Your sample uses the following code:

    $conn = new \React\Socket\Connection($handle, $loop);

    Could you try to replace this with the following?

    $conn = new \React\Stream\Stream($handle, $loop);
  4. andreme commented on Nov 7, 2014

    @andreme
    Author

    @clue
    That helps, onData is called again once with $data == '', and then the client exits.
    Am I using the wrong class? I'm not quite sure what the real difference is between them.

    I think I took it from the example here: https://github.com/reactphp/socket

  5. clue commented on Nov 7, 2014

    @clue
    Member

    Great, glad this solved the issue you were having!

    The React\Socket namespace is part of the react/socket package which is a "Library for building an evented socket server". Hence the React\Socket\Connection should be used for an incoming connection and not for an outgoing one. And yes, this clearly needs a better documentation :)

    By the way, if you want to create an outgoing connection, I highly recommend using the react/socket-client package instead of handling the underlying Stream yourself. I assume this is a pretty common requirement, so we should probably also mention this in this project's readme.

  6. andreme commented on Nov 12, 2014

    @andreme
    Author

    Thanks guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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