Skip to content

Unreliable SIGINT delivery #17706

@maleadt

Description

@maleadt

Calling kill(self, 2) in 0.5 is unreliable:

ccall(:kill, Void, (Cint, Cint,), getpid(), 2)

Running this snippet results in different possible errors:

signal (2): Interrupt
while loading no file, in expression starting on line 0
anonymous at ./<missing> (unknown line)
jl_call_method_internal at /home/tbesard/Projects/Julia/src/julia_internal.h:178 [inlined]
jl_toplevel_eval_flex at /home/tbesard/Projects/Julia/src/toplevel.c:569
jl_parse_eval_all at /home/tbesard/Projects/Julia/src/ast.c:717
jl_load at /home/tbesard/Projects/Julia/src/toplevel.c:596 [inlined]
jl_load_ at /home/tbesard/Projects/Julia/src/toplevel.c:605
signal (2): Interrupt
while loading no file, in expression starting on line 0
jl_unbox_int64 at /home/tbesard/Projects/Julia/src/alloc.c:1179
jl_f_getfield at /home/tbesard/Projects/Julia/src/builtins.c:689
signal (2): Interrupt
while loading no file, in expression starting on line 0
signal (11): Segmentation fault
while loading no file, in expression starting on line 0

None of them properly delivering the SIGINT.

Meanwhile, on 0.4:

$ julia crash.jl
$ echo $?
130     # indicates SIGINT

This is a reduced test-case from core.jl, which in its current form it only fails when running under ASAN:

function crash()
    ccall(:jl_exit_on_sigint, Void, (Cint,), 0)
    try
        ccall(:kill, Void, (Cint, Cint,), getpid(), 2)
        for i in 1:10
            Libc.systemsleep(0.1)
            ccall(:jl_gc_safepoint, Void, ()) # wait for SIGINT to arrive
        end
    catch ex
        isa(ex, InterruptException) || rethrow(ex)
    end
    ccall(:jl_exit_on_sigint, Void, (Cint,), 1)
end

crash()
ASAN:DEADLYSIGNAL
=================================================================
==17111==ERROR: AddressSanitizer: SEGV on unknown address 0x7fed15b90000 (pc 0x7fecf6cc140e bp 0x7ffe17280530 sp 0x7ffe172803b0 T0)
    #0 0x7fecf6cc140d  (<unknown module>)
    #1 0x7fecf6cc154f  (<unknown module>)
    #2 0x7fed244605d0 in jl_call_method_internal /home/tbesard/Projects/Julia/src/julia_internal.h:178:16
    #3 0x7fed244694c2 in jl_apply_generic /home/tbesard/Projects/Julia/src/gf.c:1928:23
    #4 0x7fed244bf131 in do_call /home/tbesard/Projects/Julia/src/interpreter.c:66:26
    #5 0x7fed244b5cbf in eval /home/tbesard/Projects/Julia/src/interpreter.c:190:16
    #6 0x7fed244b50f1 in jl_interpret_toplevel_expr /home/tbesard/Projects/Julia/src/interpreter.c:31:12
    #7 0x7fed2451d436 in jl_toplevel_eval_flex /home/tbesard/Projects/Julia/src/toplevel.c:558:26
    #8 0x7fed2448fc71 in jl_parse_eval_all /home/tbesard/Projects/Julia/src/ast.c:717:26
    #9 0x7fed2451f970 in jl_load /home/tbesard/Projects/Julia/src/toplevel.c:596:12
    #10 0x7fed2451fb9a in jl_load_ /home/tbesard/Projects/Julia/src/toplevel.c:605:23
    #11 0x7fed13335361 in julia_include_from_node1_19006 loading.jl:426
    #12 0x7fed1333552b in jlcall_include_from_node1_19006 (/home/tbesard/Projects/Julia/build/sanitize/usr/lib/julia/sys-debug.so+0x30952b)
    #13 0x7fed244605d0 in jl_call_method_internal /home/tbesard/Projects/Julia/src/julia_internal.h:178:16
    #14 0x7fed244694c2 in jl_apply_generic /home/tbesard/Projects/Julia/src/gf.c:1928:23
    #15 0x7fed1336b061 in julia_process_options_20109 client.jl:262
    #16 0x7fed1336d5ea in julia__start_20103 client.jl:318
    #17 0x7fed1336e178 in jlcall__start_20103 (/home/tbesard/Projects/Julia/build/sanitize/usr/lib/julia/sys-debug.so+0x342178)
    #18 0x7fed244605d0 in jl_call_method_internal /home/tbesard/Projects/Julia/src/julia_internal.h:178:16
    #19 0x7fed244694c2 in jl_apply_generic /home/tbesard/Projects/Julia/src/gf.c:1928:23
    #20 0x4dd344 in jl_apply /home/tbesard/Projects/Julia/ui/../src/julia.h:1392:12
    #21 0x4dcb3c in true_main /home/tbesard/Projects/Julia/ui/repl.c:112:9
    #22 0x4dc9ad in main /home/tbesard/Projects/Julia/ui/repl.c:232:15
    #23 0x7fed23134740 in __libc_start_main (/usr/lib/libc.so.6+0x20740)
    #24 0x4190c8 in _start (/home/tbesard/Projects/Julia/build/sanitize/usr/bin/julia-debug+0x4190c8)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (<unknown module>) 
==17111==ABORTING

I'm not sure what's happening, but there seems to be an issue with the SIGINT delivery. If I transform the above test-case, ASAN sometimes spits out more information. In those cases, it traps a use-after-free on a known address, with those addresses always being freed by some trace starting at __cxa_finalize. So it looks like the SIGUSR2 thrown by jl_try_deliver_sigint causes the world to collapse?

cc @yuyichao

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions