Error in atexit() when stopping with SIGTERM signal

Hi, I am running a compiled julia application in a docker container. In the application code I am registering a zero argument function closeAll by calling the atexit(closeAll). The closeAll function should be called before the application exits. Stopping the container with a SIGINT signal runs as expected. However, I am getting an error inside the closeAll function if stopping the container with a SIGTERM signal.

Is there any reason why stopping with these two signals behaves differently? Why do I get an error when stopping with SIGTERM signal?

Simplified example:

module LightPkg

function real_main()
atexit(closeAll)
while true
print(“.”)
sleep(1)
end
end

function closeAll()
println(“EXIT”)
end

function julia_main()
try
println(“START”)
real_main()
catch
println(“\nCATCH”)
return 1
end
return 0
end

end

By stopping the container with SIGINT signal

docker kill --signal=SIGINT container_name

I get the following logs from container:

START
…
CATCH
EXIT

I would expect the same logs when stopping with SIGTERM signal

docker kill --signal=SIGTERM container_name

but I get an error:

START
…
signal (15): Terminated
in expression starting at none:0
epoll_pwait at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
uv__io_poll at /workspace/srcdir/libuv/src/unix/linux-core.c:270
uv_run at /workspace/srcdir/libuv/src/unix/core.c:359
jl_task_get_next at /buildworker/worker/package_linux64/build/src/partr.c:473
poptask at ./task.jl:704
wait at ./task.jl:712 [inlined]
wait at ./condition.jl:106
_trywait at ./asyncevent.jl:110
wait at ./asyncevent.jl:128 [inlined]
sleep at ./asyncevent.jl:213 [inlined]
real_main at /LightPkg/src/LightPkg.jl:8
julia_main at /LightPkg/src/LightPkg.jl:19
julia_main at ./none:32
unknown function (ip: 0x7fbbc7f852ac)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2231 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
julia_main at /LightPkg/app/bin/LightPkg.so (unknown line)
main at /LightPkg/app/bin/LightPkg (unknown line)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
_start at /LightPkg/app/bin/LightPkg (unknown line)
unknown function (ip: (nil))
Allocations: 2545 (Pool: 2536; Big: 9); GC: 0
EXITschedule: Task not runnable
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] schedule(::Task, ::Any; error::Bool) at ./task.jl:591
[3] schedule at ./task.jl:586 [inlined]
[4] uv_writecb_task(::Ptr{Nothing}, ::Int32) at ./stream.jl:1051
[5] poptask(::Base.InvasiveLinkedListSynchronized{Task}) at ./task.jl:704
[6] wait at ./task.jl:712 [inlined]
[7] uv_write(::Base.TTY, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:933
[8] unsafe_write(::Base.TTY, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:1005
[9] write at ./strings/io.jl:183 [inlined]
[10] print at ./strings/io.jl:185 [inlined]
[11] print(::Base.TTY, ::String, ::Char) at ./strings/io.jl:46
[12] println(::Base.TTY, ::String) at ./strings/io.jl:73
[13] println(::String) at ./coreio.jl:4
[14] closeAll() at /LightPkg/src/LightPkg.jl:13
[15] _atexit() at ./initdefs.jl:316

I am including also the Dockerfile

FROM julia:1.5.3 AS builder

RUN apt-get update && apt-get install -y --no-install-recommends
build-essential

WORKDIR /LightPkg
COPY src src
COPY Project.toml .

RUN julia -e “using Pkg; pkg"add PackageCompiler@v1.2.3; st"; using PackageCompiler; create_app(".", "app")”

ENTRYPOINT [“/LightPkg/app/bin/LightPkg”]

2 Likes