"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
fix deadlock in tog after Ctrl-C
To:
gameoftrees@openbsd.org
Date:
Mon, 24 Oct 2022 10:39:57 +0200

Download raw body.

Thread
Loading commits for a single file in a deep history can take a long time.

Trying to abort commit loading with Ctrl-C can currently cause 'tog log'
to get stuck, waiting for got-read-pack to exit, while got-read-pack is
trying to send more commits to tog; See stack traces below.
This is a dead-lock situation and the user must resort to kill -9
to resolve it.

The patch below fixes this by closing the parent's side of the imsg
pipe before it waits for the child process to exit. Ctrl-C now results
in a brief "unexpected end of file" error from got-read-pack flashing up
before tog exists as expected.

Ok?

diff /home/stsp/src/got
commit - bc854c7bc75429b27c69c3d76a040b8c428799ad
path + /home/stsp/src/got
blob - b23e07e8e54eaf89df334656dbd6aa25515290d2
file + lib/pack.c
--- lib/pack.c
+++ lib/pack.c
@@ -791,7 +791,7 @@ pack_stop_privsep_child(struct got_pack *pack)
 static const struct got_error *
 pack_stop_privsep_child(struct got_pack *pack)
 {
-	const struct got_error *err = NULL;
+	const struct got_error *err = NULL, *close_err = NULL;
 
 	if (pack->privsep_child == NULL)
 		return NULL;
@@ -799,9 +799,12 @@ pack_stop_privsep_child(struct got_pack *pack)
 	err = got_privsep_send_stop(pack->privsep_child->imsg_fd);
 	if (err)
 		return err;
+	if (close(pack->privsep_child->imsg_fd) == -1)
+		close_err = got_error_from_errno("close");
 	err = got_privsep_wait_for_child(pack->privsep_child->pid);
-	if (close(pack->privsep_child->imsg_fd) == -1 && err == NULL)
-		err = got_error_from_errno("close");
+	if (close_err && err == NULL)
+		err = close_err;
+	imsg_clear(pack->privsep_child->ibuf);
 	free(pack->privsep_child->ibuf);
 	free(pack->privsep_child);
 	pack->privsep_child = NULL;


(gdb) bt
#0  _thread_sys_sendmsg () at /tmp/-:3
#1  0x000006b6e7b2110e in _libc_sendmsg_cancel (s=3, msg=0x7f7ffffad530, flags=0) at /usr/src/lib/libc/sys/w_sendmsg.c:27
#2  0x000006b71319e37e in msgbuf_write (msgbuf=0x7f7ffffbd8f0) at /usr/src/lib/libutil/imsg-buffer.c:277
#3  0x000006b71319af62 in imsg_flush (ibuf=0x7f7ffffad8d0) at /usr/src/lib/libutil/imsg.c:290
#4  0x000006b455d11417 in flush_imsg (ibuf=0x7f7ffffad8d0) at /home/stsp/src/got/libexec/got-read-pack/../../lib/privsep.c:198
#5  0x000006b455d1139f in got_privsep_flush_imsg (ibuf=0x7f7ffffad8d0) at /home/stsp/src/got/libexec/got-read-pack/../../lib/privsep.c:209
#6  0x000006b455d003f1 in send_traversed_commits (commit_ids=0x6b69a1c3000, ncommits=818, ibuf=0x7f7ffffad8d0) at /home/stsp/src/got/libexec/got-read-pack/got-read-pack.c:584
#7  0x000006b455cfe80e in commit_traversal_request (imsg=0x7f7ffffad8b0, ibuf=0x7f7ffffad8d0, pack=0x6b6ad5856c0, packidx=0x6b6ad570080, objcache=0x7f7ffffad868) at /home/stsp/src/got/libexec/got-read-pack/got-read-pack.c:661
#8  0x000006b455cfcb52 in main (argc=2, argv=0x7f7ffffbd988) at /home/stsp/src/got/libexec/got-read-pack/got-read-pack.c:2028
(gdb) up



(gdb) bt
#0  _thread_sys_wait4 () at /tmp/-:3
#1  0x0000094b8b3e5a9e in _libc_wait4_cancel (wpid=81169, status=0x7f7ffffbfa68, options=0, rusage=0x94b8b40316a <_thread_sys_wait4+10>) at /usr/src/lib/libc/sys/w_wait4.c:27
#2  0x00000948dc789b36 in got_privsep_wait_for_child (pid=81169) at /home/stsp/src/got/tog/../lib/privsep.c:91
#3  0x00000948dc786bf8 in pack_stop_privsep_child (pack=0x94bcd99f968) at /home/stsp/src/got/tog/../lib/pack.c:802
#4  0x00000948dc786a7a in got_pack_close (pack=0x94bcd99f968) at /home/stsp/src/got/tog/../lib/pack.c:816
#5  0x00000948dc7991a0 in got_repo_close (repo=0x94bcd99f470) at /home/stsp/src/got/tog/../lib/repository.c:787
#6  0x00000948dc75badb in stop_log_thread (s=0x94bcd9c7090) at /home/stsp/src/got/tog/tog.c:3036
#7  0x00000948dc757468 in close_log_view (view=0x94bcd9c7000) at /home/stsp/src/got/tog/tog.c:3063
#8  0x00000948dc75628b in view_close (view=0x94bcd9c7000) at /home/stsp/src/got/tog/tog.c:811
#9  0x00000948dc755e8c in view_loop (view=0x94bcd9c7000) at /home/stsp/src/got/tog/tog.c:1840
#10 0x00000948dc75338e in cmd_log (argc=1, argv=0x94aef14ee58) at /home/stsp/src/got/tog/tog.c:4050
#11 0x00000948dc752bd1 in tog_log_with_path (argc=4, argv=0x7f7ffffbff10) at /home/stsp/src/got/tog/tog.c:9251
#12 0x00000948dc752445 in main (argc=1, argv=0x7f7ffffbff10) at /home/stsp/src/got/tog/tog.c:9364
(gdb)