From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mathieu Othacehe Subject: (guix git) and guile-git finalizers. Date: Mon, 12 Jun 2017 14:44:48 +0200 Message-ID: <86h8zliddr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKOiG-0007Nj-Vq for guix-devel@gnu.org; Mon, 12 Jun 2017 08:45:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKOiB-00047N-6V for guix-devel@gnu.org; Mon, 12 Jun 2017 08:44:57 -0400 List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel Cc: Amirouche Hi ! While integrating (guix git) into Cuirass, I noticed unexpected segfaults during "latest-repository-commit" evaluation. Segfaults can be narrowed to the following lines: --8<---------------cut here---------------start------------->8--- (use-modules (git)) (begin (libgit2-init!) (let ((rep (repository-open "some-git-repo"))) (remote-fetch (remote-lookup rep "origin"))) (libgit2-shutdown)) --8<---------------cut here---------------end--------------->8--- Note that, it's not 100% reproducible, but re-executing 4 or 5 times the above snippet is often enough to observe the segfault. Here's the gdb backtrace I collected : --8<---------------cut here---------------start------------->8--- #0 0x00007fffef7eb181 in git_mwindow_put_pack () from /gnu/store/ilaffvq27kfy2la235hddkxcalj9r #1 0x00007fffef7f2897 in pack_backend(float, long double,...)(...) () from /gnu/store/ilaffvq2 #2 0x00007fffef7eef72 in git_odb_free () from /gnu/store/ilaffvq27kfy2la235hddkxcalj9r2i7-libg #3 0x00007fffef8134ce in git_repository.cleanup () from /gnu/store/ilaffvq27kfy2la235hddkxcalj #4 0x00007fffef81351a in git_repository_free () from /gnu/store/ilaffvq27kfy2la235hddkxcalj9r2 #5 0x00007ffff7b01e37 in chained_finalizer () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs #6 0x00007ffff785170f in GC_invoke_finalizers () from /gnu/store/j4p7cnxb6byf1wra3yz6pk8av4g5m #7 0x00007ffff7b02099 in scm_run_finalizers () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dx #8 0x00007ffff7b020f5 in finalization_thread_proc () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k #9 0x00007ffff7af2cba in c_body () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs-guile-2.2. #10 0x00007ffff7b680c9 in vm_debug_engine () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs-g #11 0x00007ffff7b752aa in scm_call_n () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs-guile- #12 0x00007ffff7b644e6 in catch () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs-guile-2.2.2 #13 0x00007ffff7af32a0 in scm_i_with_continuation_barrier () from /gnu/store/5zx29y44nrqj0s8h3j #14 0x00007ffff7af3335 in scm_c_with_continuation_barrier () from /gnu/store/5zx29y44nrqj0s8h3j #15 0x00007ffff7b6310c in with_guile () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs-guile- #16 0x00007ffff7858732 in GC_call_with_stack_base () from /gnu/store/j4p7cnxb6byf1wra3yz6pk8av4 #17 0x00007ffff7b63498 in scm_with_guile () from /gnu/store/5zx29y44nrqj0s8h3jlvlj82k8hj4dxs-gu #18 0x00007ffff7625454 in start_thread () from /gnu/store/rmjlycdgiq8pfy5hfi42qhw3k7p6kdav-glib #19 0x00007ffff5fed7bf in clone () from /gnu/store/rmjlycdgiq8pfy5hfi42qhw3k7p6kdav-glibc-2.25/ --8<---------------cut here---------------end--------------->8--- I supposed that what happends is the following race-condition : * (libgit2-shutdown) is called * the finalizer %repository-free is called in an other thread. * because shutdown has already been called the finalizer fails and segfaults. Maybe the right answer is to disable auto finalization and call run-finalizers as described here : https://www.gnu.org/software/guile/manual/html_node/Foreign-Object-Memory-Management.html#Foreign-Object-Memory-Management However I can't find guile counterparts for those libguile functions. WDYT ? Thanks, Mathieu