reactphp / stream

Event-driven readable and writable streams for non-blocking I/O in ReactPHP.
https://reactphp.org/stream/
MIT License
618 stars 62 forks source link

Fix `drain` event of `ThroughStream` to handle potential race condition #171

Closed clue closed 11 months ago

clue commented 12 months ago

This changeset fixes a potential race condition that may happen for the drain event of ThroughStream. This is more of an edge case when pausing/resuming/closing immediately after flushing any buffers and is unlikely to have significant impact on existing code out in the wild.

The changes look relatively simple, most of the work went into making sure this is fully covered by additional tests for such edge cases. The test suite confirms this does not affect any of the existing behavior, so this should be safe to apply.