amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.
https://amphp.org/byte-stream
MIT License
363 stars 31 forks source link

Can cause infinite loop in caller code #62

Closed Ekstazi closed 5 years ago

Ekstazi commented 5 years ago

https://github.com/amphp/byte-stream/blob/22113f2f14ae16928b8e8ade29b161d08f3031ba/lib/ResourceInputStream.php#L121

In some rare cases if caller code doesn't check for null this may cause infinite loop and amp loop will not work.

Need to use immediateWatcher instead. This may also affects output stream.

Also see related ticket: https://github.com/amphp/ssh/issues/16

kelunik commented 5 years ago

I think an infinite loop here is better, because it makes you aware of that coding error. Using an immediate watcher just hides the problem.

kelunik commented 5 years ago

I don't think we can do anything here to improve the situation without breaking the interface. I think the best thing to do would be throwing an exception if read() is called repeatedly and returned null before.