Hi,
When reading the stdout from an external program, we sometimes encounter a deadlock (if that’s the correct word). We can reproduce it with a very stripped down example, by just reading a large file (using cat) and reading the stream:
using FileIO
function load(s::Pipe)
@show s
a = read(s)
@show summary(a)
end
open(load, `cat libLAS_1.2.laz`, "r")
Run this multiple times:
for i in `seq 1 1000`;
do
echo $i; julia test_deadlock.jl; echo $i
done
When running this (using provided loop in bash), eventually the julia process will hang, not showing any output at all. Looking at a strace of both the child process and julia itself (using a mac here):
Julia Call graph:
2698 Thread_5295470 DispatchQueue_1: com.apple.main-thread (serial)
+ 2698 start_task (in libjulia.0.5.2.dylib) + 356 [0x1001e3a54] task.c:254
+ 2698 jl_apply_generic (in libjulia.0.5.2.dylib) + 1000 [0x1001c5608] .julia_internal.h:211
+ 2698 ??? (in <unknown binary>) [0x314039390]
+ 2698 ??? (in <unknown binary>) [0x31403937a]
+ 2698 jl_apply_generic (in libjulia.0.5.2.dylib) + 1000 [0x1001c5608] .julia_internal.h:211
+ 2698 jlcall_wait_20332 (in sys.dylib) + 12 [0x101bf9f7c]
+ 2698 julia_wait_20332 (in sys.dylib) + 264 [0x101bf9ed8] .event.jl:27
+ 2698 julia_wait_20334 (in sys.dylib) + 394 [0x101bf963a] .event.jl:147
+ 2698 julia_process_events_20337 (in sys.dylib) + 161 [0x101bf91b1] .libuv.jl:82
+ 2698 uv_run (in libjulia.0.5.2.dylib) + 223 [0x1002a064f] core.c:354
+ 2698 uv__io_poll (in libjulia.0.5.2.dylib) + 1815 [0x1002be5b7] kqueue.c:160
+ 2698 kevent (in libsystem_kernel.dylib) + 10 [0x7fffbfdb8d96]
and
Cat Call graph:
2762 Thread_5295491 DispatchQueue_1: com.apple.main-thread (serial)
2762 start (in libdyld.dylib) + 1 [0x7fffbfc89235]
2762 ??? (in cat) load address 0x10e560000 + 0x16a0 [0x10e5616a0]
2762 ??? (in cat) load address 0x10e560000 + 0x19ca [0x10e5619ca]
2762 write (in libsystem_kernel.dylib) + 10 [0x7fffbfdb97e6]
It seems to hang on waiting to read from the pipe, in this case kqueue. This occurs quickly on both Julia 0.5 and 0.6, both on Linux and Mac. On Windows I can’t reproduce it with using cat, but have encountered it with running other software writing to stdout.
Could you help us figure out whether this is a bug in Julia (libuv?) or if we’re using open
wrong? Appreciate any feedback.
Cheers