-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-10092 (Internal stream casting should not emit lost bytes warning twice) #10093
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
Conversation
…arning twice) The reason why the warning was emitted is because it was not guarded via the show_err parameter. This parameter is set to false/0 via the macro function php_stream_can_cast() to check this silently. The warning is completely removed as this function in particuliar sets this parameter to 0 when it casts the streamas it "performs a cast" just to retrieve the underlying file number.
I feel that stream_select() uses the php-src/ext/standard/streamsfuncs.c Lines 634 to 636 in b9cd1cd
This appears to be its only effect, as it's only referenced here: Line 324 in b9cd1cd
In case you decide to use |
I don't think this warning should be silenced as it signals that the stream lost some data during casting. However that check doesn't seem really correct to me for all cases. I have done some debugging for the reported case (http wrapper) the There's of course another issue with emitting 2 warning which is more a bug in
In general doing can_cast directly followed by cast with suppressed warning is an anti-pattern as it is doing exactly the same thing twice... I think this should be fixed / improved independently but with a better tests that would not be online like the one here. We might need to do first the investigation to see if there are actually cases when data can be lost and possibly recreate such case in the test. Depending on the result of that, the change in |
Thanks for the detailed explanation, I will try and figure out a test that is not online, but I'm also wondering if doing both casts isn't already a bug in itself? Because I would expect that if the cast to |
This is mostly true for all core streams. The only exception is the ssl one: Lines 2534 to 2557 in 383053c
It can theoretically fail for I think that in case of |
Data loss or corruption would happen if we attempted to read or write from the file descriptor after casting, because this would not reflect the buffered data. For instance, this script loses buffered data. I think that the warning is legit, but the wording could be improved. Regarding posix_isatty(), it's correct to silence the warning because we do not read or write from the file descriptor. stream_select() silences the warning for the same reason. |
@arnaud-lb Ah ok I got it now. I completely misunderstood it and thought that it was about loosing data when doing the conversion. I think the |
Closing in favour of #10173 |
The reason why the warning was emitted is that it was not guarded via the show_err parameter.
This parameter is set to false/0 via the macro function php_stream_can_cast() to check this silently.
The warning is completely removed as this function in particular sets this parameter to 0 when it casts the streams, it "performs a cast" just to retrieve the underlying file number.