Skip to content
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

check pipe initialization using a status code #10469

Closed
wants to merge 1 commit into from

Conversation

bicycle1885
Copy link
Member

Checking initialization of a pipe with its handler can cause false-positive assertion error when STDIN is piped (ref: #8529).
This seems to be caused by immediate release of a handler of the pipe after reading all data from it (ref: #8529 (comment)).
The .status field of a Pipe can distinguish "once initialized" pipes from "never initialized" ones.
This issue may be related to #6957 as well.

@Keno
Copy link
Member

Keno commented Mar 11, 2015

I guess this will end up passing /dev/null to the child process? I guess that's not unreasonable if all the data has been read.

@bicycle1885
Copy link
Member Author

No the same as passing /dev/null. But this will have the same effect if a pipe is closed.
I think it is problematic that behavior changes depending on the sizes of an input and a pipe buffer:

pipe.jl

line = readline(STDIN)
@show STDIN
print(line)
println("-- "^20)
run(pipe(STDIN, `head`))

large input:

~/v/julia (fix-pipe-check|…) $ cat base/*.jl | ./julia pipe.jl
STDIN = Pipe(active, 271306 bytes waiting)
module Dates
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# get and set current directory

function pwd()
    b = Array(UInt8,1024)
    len = Csize_t[length(b),]
    uv_error(:getcwd, ccall(:uv_cwd, Cint, (Ptr{UInt8}, Ptr{Csize_t}), b, len))
    bytestring(b[1:len[1]-1])
end

small input:

~/v/julia (fix-pipe-check|…) $ cat base/build_h.jl | ./julia pipe.jl
STDIN = Pipe(closed, 492 bytes waiting)
# This file is automatically generated in base/Makefile
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
```.

But I think this is a separated problem.

@@ -293,7 +293,7 @@ macro setup_stdio()
close_in,close_out,close_err = false,false,false
in,out,err = stdios
if isa(stdios[1], Pipe)
if stdios[1].handle == C_NULL
if stdios[1].status == StatusUninit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be using the test isopen(stdios[1])

@JeffBezanson
Copy link
Member

fixed by 322ff51.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants