-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
write(...)
output "torn" after a partial write
#57011
Comments
In the general case, this kind of in-band messaging is not sufficient because there may be a valid message containing that exact spare byte as well. If whatever in-band escape mechanism you use, as well as any data after the fake End Of Message marker, is dropped, you still get a corrupted message on the reading end. This is probably fine for IOBuffer (which only starts dropping data once its full), but may be problematic for some other non-blocking IO. |
I think it isn't typically an issue for IOBuffer, since once it is full, it remains full, so the remaining text is also dropped, similar to if you had written to |
Originally posted by @Seelengrab in #56980 (comment)
That comment is about
write(::IO, ::Char)
. This also happens in ourwrite
implementation for AbstractArray:If any of those writes execute partially, we blindly continue writing all following elements and can "tear" the result, leading to incomplete and/or invalid text and data. This is not an issue for many IO types which do a complete write or throw an error, but IOBuffers are a notable exception and one can imagine in-memory buffers that asynchronously drain which could hit this pretty easily as well.
A related defect is that a caller of
print(io, ...)
has no way to detect partial writes of a text representation of an object. In the past, I've had to leave a spare byte in the fixed-sizeIOBuffer
and check whether it reached capacity to work around this.The text was updated successfully, but these errors were encountered: