Fix closing socket resource before removing from loop #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, this component implicitly calls
fclose()
on the underlying socket resource before actually closing the stream (and removing it from the event loop). This code is in place ever since #99 has been merged, but the error didn't really manifest itself until recently, when reactphp/stream#121 landed.This issue can easily be reproduced by using latest react/stream with
ext-event
installed. If you have outgoing data pending on a connection, but the connection is detected to be closed by the remote peer, this would cause an uncaught exception.This PR ensures we do not call
fclose()
on the socket resource prior to actually invoking the close logic and removing it from the event loop. I've added some tests to try to highlight this issue to avoid any future regressions.Note that we've recently introduced a related fix in the underlying event loop via reactphp/event-loop#139. That one ensures the loop will not actually complain about this situation and silently remove the invalid stream resource. Despite this relevant fix, it still makes sense to fix the root cause here.
Fixes reactphp/event-loop#136