git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t9300-fast-import: don't hang if background fast-import exits too early

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Dec 1, 2019, 09:31 UTC
Message-ID
<20191201093148.GH23183@szeder.dev>
In-Reply-To
<xmqqsgm512vl.fsf@gitster-ct.c.googlers.com>
On Sat, Nov 30, 2019 at 01:16:30PM -0800, Junio C Hamano wrote:
Show 29 quoted lines
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
> > +	(
> > +		git fast-import $options <&8 >&9 &
> > +		echo $! >V.fi.pid
> > +		wait $!
> > +		echo >&2 "background fast-import terminated too early with exit code $?"
> > +		# Un-block the read loop in the main shell process.
> > +		echo >&9 UNEXPECTED
> > +	) &
> > +	echo $! >V.sh.pid
> >  	# We don't mind if fast-import has already died by the time the test
> >  	# ends.
> > -	test_when_finished "
> > +	test_when_finished '
> >  		exec 8>&-; exec 9>&-;
> > -		kill $(cat V.pid) && wait $(cat V.pid)
> > -		true"
> > +		kill $(cat V.sh.pid) && wait $(cat V.sh.pid)
> > +		kill $(cat V.fi.pid) && wait $(cat V.sh.pid)
> > +		true'
> 
> The original interpolates the PID of the fast-import when
> "when-finished" program is registered, so it is OK if somebody else
> removed V.pid file; the new one interpolates when "when-finished"
> program is run, reading from V.??.pid, so somebody needs to make
> sure these pid files will stay around.  I do not think it is an
> issue as I suspect we've left it to the global clean-up procedure
> that removes the trash directory to remove the pid file.

In the original the same shell process starts 'git fast-import', writes its pidfile, and registers the test_when_finished commands, so we can be sure that the pid file is already present when the shell runs the $(cat V.pid) command substitutions.

With this patch that's not the case anymore, because the background subshell starts 'git fast-import' and writes the pidfile, but the main shell process registers the test_when_finished commands. IOW these two shell processes are racing, and it's possible that the test_when_finished command is executed before the background subshell can write the pidfile. So double quotes around the block of test_when_finished commands are not good.

> By the way, does the second "kill && wait" wait for the right
> process?

Ouch, it clearly doesn't. Copy-paste error I suppose. Thanks for spotting it.

Show 9 quoted lines
> 
> >  background_import_still_running () {
> > -	if ! kill -0 "$(cat V.pid)"
> > +	if ! kill -0 "$(cat V.fi.pid)"
> >  	then
> >  		echo >&2 "background fast-import terminated too early"
> >  		false
> >  	fi
> >  }
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 7 in “t9300-fast-import: don't hang if background fast-import exits too early”
  1. t9300-fast-import: don't hang if background fast-import exits too earlySZEDER Gábor, Nov 30, 2019
  2. Junio C HamanoNov 30, 2019
  3. SZEDER GáborDec 1, 2019
  4. Junio C HamanoDec 1, 2019
  5. 0/2 t9300-fast-import: don't hang if background fast-import exits too earlySZEDER Gábor, Dec 6, 2019
  6. 1/2 t9300-fast-import: store the PID in a variable instead of pidfileSZEDER Gábor, Dec 6, 2019
  7. 2/2 t9300-fast-import: don't hang if background fast-import exits too earlySZEDER Gábor, Dec 6, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.