# My julia code has segfault only on exit - is there a way to simply stop julia without calling into this finalization stuff

**URL:** <https://discourse.julialang.org/t/my-julia-code-has-segfault-only-on-exit-is-there-a-way-to-simply-stop-julia-without-calling-into-this-finalization-stuff/106538>\
**Category:** General Usage\
**Tags:** question, rcall, finalization\
**Created:** [November 21, 2023, 3:52pm UTC](https://discourse.julialang.org/t/my-julia-code-has-segfault-only-on-exit-is-there-a-way-to-simply-stop-julia-without-calling-into-this-finalization-stuff/106538 "2023-11-21T15:52:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [November 21, 2023, 3:52pm UTC](https://discourse.julialang.org/t/my-julia-code-has-segfault-only-on-exit-is-there-a-way-to-simply-stop-julia-without-calling-into-this-finalization-stuff/106538/1 "2023-11-21T15:52:56Z")

</div>

I just opened an issue for a segmentation fault with RCall which only happens on exit

> <https://github.com/JuliaInterop/RCall.jl/issues/511>
>
> Hello,
> I just want to report that I run into a segmentation fault when closing …Julia again (aftr using RCall).
> 
> \`\`\`
> \[1847\] signal (11.1): Segmentation fault
> in expression starting at none:0
> ijl\_eh\_restore\_state at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/rtutils.c:265
> \_atexit at ./initdefs.jl:416
> jfptr\_\_atexit\_46096.clone\_1 at /usr/local/julia/lib/julia/sys.so (unknown line)
> \_jl\_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 \[inlined\]
> ijl\_apply\_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
> jl\_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 \[inlined\]
> ijl\_atexit\_hook at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/init.c:280
> jl\_repl\_entrypoint at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/jlapi.c:718
> main at julia (unknown line)
> unknown function (ip: 0x7f95e9ce41c9)
> \_\_libc\_start\_main at /lib/x86\_\[64\](https://github.com/jolin-io/JolinWorkspaceTemplate/actions/runs/6945307045/job/18894379623?pr=54#step:11:65)-linux-gnu/libc.so.6 (unknown line)
> unknown function (ip: 0x4010b8)
> Allocations: 32734049 (Pool: 32\[70\](https://github.com/jolin-io/JolinWorkspaceTemplate/actions/runs/6945307045/job/18894379623?pr=54#step:11:71)1\[76\](https://github.com/jolin-io/JolinWorkspaceTemplate/actions/runs/6945307045/job/18894379623?pr=54#step:11:77)1; Big: 32288); GC: 42
> \`\`\`
> 
> I have no minimal example, but I guess it could have something todo with me using an R function inside an async julia task, which somehow is not correctly finalized or prevents some other part from finalizing.
> 
> The above error occurs on a docker container build on top julia:1.9, while when I run it on my local laptop, the same code does not throw an error, but hangs infinitely.

I would like to find a workaround, i.e. somehow kill Julia without running into those finalizers which cause segmentation fault.

It is really funny that everything works, only exiting Julia is the difficult part

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [November 22, 2023, 7:08am UTC](https://discourse.julialang.org/t/my-julia-code-has-segfault-only-on-exit-is-there-a-way-to-simply-stop-julia-without-calling-into-this-finalization-stuff/106538/2 "2023-11-22T07:08:40Z")

</div>

Crashing on exit is not unheard of when interoperating with other languages. For example [loading pytorch causes invalid pointer crash on free() · Issue #973 · JuliaPy/PyCall.jl · GitHub](https://github.com/JuliaPy/PyCall.jl/issues/973) was probably caused by clashing dependencies loaded by Julia and Python. Your backtrace looks different but maybe you can find some ideas for investigation in the issue comments.
