# Error in atexit() when stopping with SIGTERM signal

**URL:** https://discourse.julialang.org/t/error-in-atexit-when-stopping-with-sigterm-signal/60486
**Category:** General Usage
**Tags:** error, deployment, atexit
**Created:** [May 3, 2021, 9:37pm UTC](https://discourse.julialang.org/t/error-in-atexit-when-stopping-with-sigterm-signal/60486 "2021-05-03T21:37:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kubcoporubco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kubcoporubco/32/24703_2.png) [@kubcoporubco](https://discourse.julialang.org/u/kubcoporubco)
#### Post date: [May 3, 2021, 9:37pm UTC](https://discourse.julialang.org/t/error-in-atexit-when-stopping-with-sigterm-signal/60486/1 "2021-05-03T21:37:33Z")

</div>

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”]
