-
-
Couldn't load subscription status.
- Fork 5.7k
Description
julia> io = Base.BufferStream()
BufferStream(bytes waiting=0, isopen=true)
julia> let
t = @async begin
for _ = 1:10
bytes = readavailable(io)
@show (String(bytes), eof(io), isopen(io))
end
end
run(pipeline(`echo "hi"`, stdout=io))
run(pipeline(`echo "bye"`, stdout=io))
end
(String(bytes), eof(io), isopen(io)) = ("hi\n", true, false) # EOF is true here
(String(bytes), eof(io), isopen(io)) = ("bye\n", true, false) # we get more bytes out here
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
(String(bytes), eof(io), isopen(io)) = ("", true, false)
Process(`echo bye`, ProcessExited(0))The docs for eof say:
Test whether an I/O stream is at end-of-file. If the stream is not yet exhausted, this function will block to wait for more data if necessary, and then return false. Therefore it is always safe to read one byte after seeing eof return false. eof will return false as long as buffered data is still available, even if the remote end of a connection is closed.
and that seems contradicted here, e.g. the stream does not seem "exhausted" but eof returns true. This example is related to #49233 (and JuliaLang/Pkg.jl#3430 (comment)) but Base.BufferStream seems to have particularly weird behavior in this case (compared to IOBuffer and Base.PipeBuffer) so I thought it was worth a separate issue.
xref #42424 which discusses other issues with Base.BufferStream