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

stop_reading causes a seg fault under certain conditions #3495

Closed
amitmurthy opened this issue Jun 22, 2013 · 5 comments
Closed

stop_reading causes a seg fault under certain conditions #3495

amitmurthy opened this issue Jun 22, 2013 · 5 comments
Labels
bug Indicates an unexpected problem or unintended behavior io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@amitmurthy
Copy link
Contributor

The code below simulates the seg fault mentioned in #3437 . It models the typical flow in multi.jl.

To simulate :

  1. Copy and execute the below code in a Julia session
function accept_sock(server::Base.TcpServer, status::Int32)
    if(status == -1)
        error("An error occured during the creation of the server")
    end
    sock = Base.accept_nonblock(server)
    process_sock(sock)
end

function add_to_workq(t::Task)
    ccall(:uv_stop,Void,(Ptr{Void},),Base.eventloop())
    unshift!(Base.Workqueue, t)
end


function process_sock(sock::AsyncStream) 
    add_to_workq(@task begin
        start_reading(sock)
        Base.wait_connected(sock)
        println("After wait_connected")
        try
            while true
                c=read(sock, Uint8)
                print(c)
            end
        catch e
            println("Caught exception $e")
            stop_reading(sock)
            return nothing
        end
    end)
end


(actual_port,sock) = open_any_tcp_port(accept_sock,8000) 
println(dec(actual_port))
  1. Open at least 3 telnet connections to the port printed above using telnet localhost 8000
  2. tickle all the connections by typing any keys in the telnet sessions
  3. execute killall telnet
  4. On the Julia session you should see :
julia> (actual_port,sock) = open_any_tcp_port(accept_sock,8000) 
(0x1f40,TcpServer(listening))

julia> println(dec(actual_port))
8000

julia> After wait_connected
After wait_connected
After wait_connected
0x610x0d0x0a0x620x0d0x0a0x630x0d0x0aCaught exception EOFError()
Caught exception EOFError()
Segmentation fault

If you remove stop_reading(sock) in the exception handler in process_sock the seg fault goes away.

cc: @JeffBezanson , @loladiro

@vtjnash
Copy link
Member

vtjnash commented Jun 22, 2013

After receiving an EOF, the stream is closed and invalid for any further operations. The functions in base need to be better about checking the state of the stream before doing operations on them, to avoid this sort of behavior.

@amitmurthy
Copy link
Contributor Author

FWIW, it does not happen when only one stream is active. I think a nice set of stress tests for IO and parallelism/concurrency is due.

@ViralBShah
Copy link
Member

+1 on better stress tests.

I agree that functions in base need to be robust about using streams, but it should certainly be possible to avoid a segfault.

@vtjnash
Copy link
Member

vtjnash commented Jul 11, 2013

related to #1923

@vtjnash
Copy link
Member

vtjnash commented Jul 11, 2013

fixed

@vtjnash vtjnash closed this as completed Jul 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

3 participants