]> git.ipfire.org Git - thirdparty/git.git/commit
index-pack: work around LSan threading race with barrier
authorJeff King <peff@peff.net>
Mon, 30 Dec 2024 04:29:38 +0000 (23:29 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Dec 2024 14:18:58 +0000 (06:18 -0800)
commit526c0a851b14d1bbec4b8d31a23d93ca0eb82637
tree567ddeefe72c4ea3868257067952b7252649259b
parent7d0037b59ae0d22a2718c28d8e70e3ef3f3f991e
index-pack: work around LSan threading race with barrier

We sometimes get false positives from our linux-leaks CI job because of
a race in LSan itself. The problem is that one thread is still
initializing its stack in LSan's code (and allocating memory to do so)
while anothe thread calls die(), taking down the whole process and
triggering a leak check.

The problem is described in more detail in 993d38a066 (index-pack: spawn
threads atomically, 2024-01-05), which tried to fix it by pausing worker
threads until all calls to pthread_create() had completed. But that's
not enough to fix the problem, because the LSan setup code runs in the
threads themselves. So even though pthread_create() has returned, we
have no idea if all threads actually finished their setup before letting
any of them do real work.

We can fix that by using a barrier inside the threads themselves,
waiting for all of them to hit the start of their main function before
any of them proceed.

You can test for the race by running:

  make SANITIZE=leak THREAD_BARRIER_PTHREAD=YesOnLinux
  cd t
  ./t5309-pack-delta-cycles.sh --stress

which fails quickly before this patch, and should run indefinitely
without it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c