Closed sbromberger closed 9 years ago
May also be related to
julia> using GnuTLS
julia> sess = GnuTLS.Session()
GnuTLS.Session(Ptr{Void} @0x00007fdbb2236200,false,#undef,#undef)
julia> set_priority_string!(sess)
julia> set_credentials!(sess, GnuTLS.CertificateStore())
julia> associate_stream(sess, connect("github.com", 443))
julia> handshake!(sess)
ERROR: MemoryError()
@Keno any ideas on this? It may have something to do with the ccall
overhaul since this is 0.4 specific?
Here's my full backtrack on OSX
julia> GnuTLS.handshake!(stream)
signal (11): Segmentation fault: 11
buffer_or_write at stream.jl:763
write at stream.jl:833
jlcapi_write_43076 at (unknown line)
_gnutls_writev_emu at /Users/jacobquinn/.julia/v0.4/Homebrew/deps/usr/lib/libgnutls.dylib (unknown line)
_gnutls_io_write_flush at /Users/jacobquinn/.julia/v0.4/Homebrew/deps/usr/lib/libgnutls.dylib (unknown line)
_gnutls_handshake_io_write_flush at /Users/jacobquinn/.julia/v0.4/Homebrew/deps/usr/lib/libgnutls.dylib (unknown line)
_gnutls_send_handshake at /Users/jacobquinn/.julia/v0.4/Homebrew/deps/usr/lib/libgnutls.dylib (unknown line)
send_hello at /Users/jacobquinn/.julia/v0.4/Homebrew/deps/usr/lib/libgnutls.dylib (unknown line)
gnutls_handshake at /Users/jacobquinn/.julia/v0.4/Homebrew/deps/usr/lib/libgnutls.dylib (unknown line)
handshake! at /Users/jacobquinn/.julia/v0.4/GnuTLS/src/GnuTLS.jl:316
jlcall_handshake!_43077 at (unknown line)
jl_apply at /Users/jacobquinn/julia/src/gf.c:1693
jl_apply at /Users/jacobquinn/julia/src/interpreter.c:53
eval at /Users/jacobquinn/julia/src/interpreter.c:214
jl_toplevel_eval_flex at /Users/jacobquinn/julia/src/toplevel.c:503
jl_eh_restore_state at /Users/jacobquinn/julia/src/./julia.h:1296
eval_user_input at REPL.jl:60
jlcall_eval_user_input_42593 at (unknown line)
jl_apply at /Users/jacobquinn/julia/src/./julia.h:1108
anonymous at task.jl:89
jl_apply at /Users/jacobquinn/julia/src/task.c:233
Segmentation fault: 11
jq-mbp:julia jacobquinn$
Actually, not sure if my git blame is off here, but I think this commit may be where this started. Any thoughts @amitmurthy?
After changing lines https://github.com/JuliaWeb/GnuTLS.jl/blob/master/src/GnuTLS.jl#L319-L320 to
old_ptr = pointer(priority)
ret = ccall((:gnutls_priority_set_direct,gnutls),Int32,(Ptr{Void},Ptr{Uint8},Ptr{Ptr{Uint8}}),s.handle,priority,x)
I can see the same problem on the latest master.
It is segfaulting at https://github.com/JuliaLang/julia/blob/master/base/stream.jl#L756, which is basically isnull(s.sendbuf)
Looking into it, but right now I have no clue as to what could be causing this. Seems like some memory corruption has happened before the handshake!
call.
Also https://github.com/JuliaLang/julia/pull/10232 was merged 25 days ago, while this issue has been reported 28 days ago. So, the underlying cause is definitely not https://github.com/JuliaLang/julia/pull/10232, but could be something a few days earlier.
What I have got so far:
I printed the object_ids of the TCPSocket in both GnuTLS.jl in associate_stream
println("0. $(object_id(s.read))")
println("0. $(object_id(s.write))")
and in the cfunction generated callback in buffer_or_write
in stream.jl
via
typeof(s) == TCPSocket && println("2. $(object_id(s))")
The object_ids are different.
They should be the same.
I think I found the cause of the segfault. The handle being passed in associate_stream
is of the GnuTLS session, while the function in stream.jl
expects an AsyncStream.
I think I know how it can be fixed.
Closed by #40
Brand new julia REPL: