🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #884

[PATCH v3 0/4] object-file: fix ".keep" lockfile ownership in ODB transactions

#884
From: Justin Tobler
Date: Tue, 20 Oct 2026 13:28
153 lines
16088 bytes
Greetings,

This series addresses a bug report[1] regarding a git-receive-pack(1)
process deleting ".keep" lockfiles of with the same name but from
another concurrent git-receive-pack(1) process receiving an identical
packfile. Deleting the ".keep" lockfile for another process leaves its
newly written packfile vulnerable to deletion by another concurrent
housekeeping process.

The root of the problem here is that the temporary ".keep" lockfiles are
generated and registered in the object quarantine prior to being written
in the primary ODB. This means that even if the ODB transaction never
commits and exits early, the tempfile atexit(3) handler still runs and
tries to delete the lockfile at its expected final location. This
blindly deletes any file matching regardless of whether is was created
by the process.

The first three patches are some preparatory changes so that
`odb_transaction_files_write_pack()` is able to start explicitly
creating the lockfiles without relying on git-index-pack(1). Patch four
migrates lockfile generation to happen during ODB transaction commit to
ensure the lockfile is actually able to be written before registering it
as a tempfile.

Changes since V2:
  - In `write_pack_lockfile()` the error is now explicitly assigned to
    `ret`.
  - Removed an added newline that was not needed.

Changes since V1:
  - Split out comment change into separate commit as suggested.
  - Improved error handling and logic flow in a couple of functions.
  - Renamed `write_pack_lock()` to `write_pack_lockfile()`.
  - Added better error messages and errno reporting to
    `write_pack_lockfile()` helper.
  - Adapted tests case to assert that packfile is not migrated.
  - Clarified some commit messages and fixed some typos.

Thanks,
-Justin

[1]: <932e8e425aecfbd33c1e5caf66c80a0226abacba.1789385483.git.gitgitgadget@gmail.com>

Justin Tobler (4):
  pack-write: make index-pack output comment hash agnostic
  pack-write: lift and expose index-pack report parsing
  object-file: explicitly write ".keep" lockfile
  object-file: write ".keep" lockfiles during transaction commit

 object-file.c              | 126 +++++++++++++++++++++++++++++--------
 pack-write.c               |  64 ++++++++++++++-----
 pack.h                     |  10 +++
 t/t5547-push-quarantine.sh |  30 ++++++++-
 4 files changed, 183 insertions(+), 47 deletions(-)

Range-diff against v2:
1:  b9197cbf3b = 1:  b9197cbf3b pack-write: make index-pack output comment hash agnostic
2:  e27679ac16 = 2:  e27679ac16 pack-write: lift and expose index-pack report parsing
3:  9236493740 ! 3:  e7f72aa53d object-file: explicitly write ".keep" lockfile
    @@ object-file.c: int read_loose_object(struct repository *repo,
     +{
     +	struct strbuf lock_path = STRBUF_INIT;
     +	struct strbuf contents = STRBUF_INIT;
    -+	int ret = -1;
    ++	int ret = 0;
     +	int fd;
     +
     +	strbuf_addf(&lock_path, "%s/pack/pack-%s.keep",
    @@ object-file.c: int read_loose_object(struct repository *repo,
     +	fd = safe_create_file_with_leading_directories(source->odb->repo,
     +						       lock_path.buf);
     +	if (fd < 0) {
    -+		error_errno(_("unable to create '%s'"), lock_path.buf);
    ++		ret = error_errno(_("unable to create '%s'"), lock_path.buf);
     +		goto out;
     +	}
     +
     +	if (write_in_full(fd, contents.buf, contents.len) < 0) {
    -+		error_errno(_("unable to write '%s'"), lock_path.buf);
    ++		ret = error_errno(_("unable to write '%s'"), lock_path.buf);
     +		close(fd);
     +		unlink(lock_path.buf);
     +		goto out;
     +	}
     +
     +	if (close(fd) < 0) {
    -+		error_errno(_("unable to close '%s'"), lock_path.buf);
    ++		ret = error_errno(_("unable to close '%s'"), lock_path.buf);
     +		unlink(lock_path.buf);
     +		goto out;
     +	}
     +
    -+	ret = 0;
    -+
     +out:
     +	strbuf_release(&lock_path);
     +	strbuf_release(&contents);
    @@ object-file.c: static int odb_transaction_files_write_pack(struct odb_transactio
      			strbuf_addstr(err_msg, "index-pack abnormal exit");
     -			return -1;
     +			goto out;
    -+		}
    -+
    + 		}
    + 
     +		if (ret) {
     +			strbuf_addstr(err_msg, "index-pack failed to report pack name");
     +			goto out;
    - 		}
    - 
    ++		}
    ++
     +		strbuf_addf(&keep_msg, "receive-pack %"PRIuMAX" on %s",
     +			    (uintmax_t)getpid(), hostname);
     +
    @@ object-file.c: static int odb_transaction_files_write_pack(struct odb_transactio
     +
      		odb_source_prepare(transaction->quarantine,
      				   ODB_PREPARE_FLUSH_CACHES);
    -+
      	}
      
     -	return 0;
4:  c1a175e2b9 ! 4:  046ff4741e object-file: write ".keep" lockfiles during transaction commit
    @@ object-file.c: static int write_pack_lockfile(struct odb_source *source, const c
      	}
      
     +	*out = register_tempfile(lock_path.buf);
    - 	ret = 0;
    - 
    ++
      out:
    + 	strbuf_release(&lock_path);
    + 	strbuf_release(&contents);
     @@ object-file.c: static int write_pack_lockfile(struct odb_source *source, const char *pack_name,
      	return ret;
      }
    @@ object-file.c: static int odb_transaction_files_write_pack(struct odb_transactio
      
      		odb_source_prepare(transaction->quarantine,
      				   ODB_PREPARE_FLUSH_CACHES);
    --
    - 	}
    - 
    +@@ object-file.c: static int odb_transaction_files_write_pack(struct odb_transaction *base,
      	ret = 0;
      
      out:

base-commit: f57c9a73884400380bddd172acc88b569834f909
-- 
2.56.0.173.gf57c9a7388
Technical Details
Message-ID: <20261020132900.1208343-1-jltobler@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72522-linux-kernel-git=dewy.ru
References: <20261016213716.593278-1-jltobler@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72522-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: [PATCH v3 0/4] object-file: fix ".keep" lockfile ownership in ODB transactions
Date: Tue, 20 Oct 2026 08:28:56 -0500
Organization: Usenet Network
Message-ID: <20261020132900.1208343-1-jltobler@gmail.com>
References: <20261016213716.593278-1-jltobler@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3861461"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pcD4F/kdxHYiJcrQWtFcJtVetH0= sha256:L06C8xmSY4bxv9b0uQGRrXrmCJIx7OxMclERBTmIfKI=
	sha1:NZNZl08KCkUABcnqA9EcJcfAnig= sha256:lEFgzBP7EhhxBIBu8H++RvYehonwLYG0vAL5W3pXdQ8=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id AB40C110D08; Tue, 20 Oct 2026 16:34:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.047
X-Spam-Status: No, score=-3.047 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jVcwwhsxjUde;
	Tue, 20 Oct 2026 16:34:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72522-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4E642110D09; Tue, 20 Oct 2026 16:34:23 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 16D5C336B4; Tue, 20 Oct 2026 13:29:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792502951;
	b=im7cUgNIFoCa6UQyzPIIABHoPoUFzstMd4DtKSN+Jo2g7kisXnGZnS6NUQsKw9Ff7Yhj
	 cYtxAaeEJO0DrQIjDPpQjY44pRB1tkWblNiOWZsn5JcbbRnazKZ3vAL1uw03D4paiJwyW
	 eavtSN3VkTjPMAlF2jMi0XWAcqTEYbAFfaWDeZOm4bFdCBBfTfPK/qLRodRUnhDjWEeI/
	 VmrXjVwS/069o86E4pHVMLgDzjt0YZPShbuMECsA15XnsoS3uVjVRwfPNNGllBEAqHjs8
	 mZXgt1uij0MjZkz/AhrTtP9KdkcRtevc6lExxyLfOf9ViVlr9ByWJ6qf5LjMeTzdKvA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792502951;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=7hU2KiZZ+KUK8qDwXMCP2jjBbbj0zDZ3giHmdMCLMlo=;
	b=srRfDxBjrol+MKUNlPqrjOFmBZBJABxlLwdqlpZvjYHoPVKUo4P23eSbmnRG5A6m7n/R
	 Jmaai4Eib9Dp+m87Le4drK8PyVzIxKydBKZtTUkJhlbEE+PemrpGoV3tl93YFntXZOtX+
	 YBrGrrgKDYQsKThWfJroeAYVdp/z9SPkBG7LDM6iwlolSdydoatbwfeznuk7ZjjTzH32D
	 nodbmerS1SIMK77JIFEssSM8wK3OyOejB/d2Pq9uBB5QSTRx6o2yW9jeNTmdNYllE6Se8
	 ztJ6kdG5PRLHz1Lx6IiNOgpMdWTtULhrYc2snD+nIQDjOH8KBA7NnzbWJ/Wd4hwQXkQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=dLu0Z8On;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 9583E606A31F;
	Tue, 20 Oct 2026 13:29:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=dLu0Z8On
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792502950;
	b=g4RdCJ+QuryGAzkhPS/YPVch3E0ihdQTaXjdCrlEoTJg65Ro/gEdEhiRlGOwgos0Br2m
	 BAH8mhWLZ6Sew9LGPJBDhlkO51N7vlvOOkdnr3+P79VNKecWwlinESf5/i9Z1W9o+Wkif
	 7JGtNG/qAbjdsAF36PuYtOQuu/dgGJTWcBAfpjIMOH4zIv960u2TaIHoW+Ce4qRp+43Dq
	 LWdm9+8thBAeSPvZJGqZP8+3nnIcI9Tl/VeVFr1qic2m29mGsKVNHjenU3uK7DJ8C8EZc
	 55BEGQMnKzNUJnz0835yNHqLMxom2skF1qPGqxYIKMgRjwUpO7M9tKPwJjVd7L7FG0Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792502950;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=7hU2KiZZ+KUK8qDwXMCP2jjBbbj0zDZ3giHmdMCLMlo=;
	b=srPbpAtC5OQr7K1trxubD/v0Kh2jSazz50KrJFcLsCGuwFuEPuIibDs1Tjp+AIYFCoq8
	 IPhGcnNCgZwR99Q1AN/15phXgp5hyEfxL0l1T0V1U47s8PA4U/YYX2GgR+10d+H9O63Wk
	 8iDUcjwgb5lRrhlGLwpTw4F2+5xSXYZCJo8Qn/+8FjinTE4O2XfZ1V8qsBLCFk32FAyoP
	 q/HlvO14yv6tG2jIDfEiEdkSyatikq5RR2PAG3mmcswdYtrVD9+Vw+KcBTldPkH44ScOQ
	 SnXgSnKSv1v3aD+daTmq/7FbMCukT7l52dFSOsJoivZTXDH37RMA6lkCV4sZ2dWUJBw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=dLu0Z8On;
	arc=none smtp.remote-ip=209.85.161.53
X-Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59B59606A319
	for <git@vger.kernel.org>; Tue, 20 Oct 2026 13:29:10 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59B59606A319
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-6aa9606ddadso2359062eaf.0
        for <git@vger.kernel.org>; Tue, 20 Oct 2026 06:29:10 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792502949; x=1793107749; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=7hU2KiZZ+KUK8qDwXMCP2jjBbbj0zDZ3giHmdMCLMlo=;
        b=dLu0Z8OnDHAEElqRKy1udX1qIeqBb0BJE+cQV5Mo4hQfLTSgo3C/43MYE02Lc0EcXa
         pq3P80eit1mAEwj/tFae58rHMM70JPFFSxQXTpFLp9uxTqRWnisxmklsNGfwOjgtQXV/
         rNM901WIh0ow1pVsZfnIziHGycBYuQLDFSbNWWwl6sITMNmbGeP8iKlc+xhtqJ8iVTwc
         41w4iEiRgCeTL/5QbIaVQg9Hp/gp2lV+cpjXLC+AGt44br+1nuMC+gR/jwVlgO03foZ0
         my9j1iOQgZJIMZdz8SUew+XejUIjuyowc1J84Ay4vqdomiyvr6Zh7B2hiA0RLDf/tddK
         jccQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792502949; x=1793107749;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=7hU2KiZZ+KUK8qDwXMCP2jjBbbj0zDZ3giHmdMCLMlo=;
        b=tokgNsLHS8l5GDuvnKnQEV9q80U2RL50b2DPRltdkdN5c1JNMY2cfNk5NgwKt6ACil
         oRlnnIN9vXNbI10xH0T/rTkKfTaYGBs/hwQ/CnIK/4Byv8ml7+7LnPYVayHGgu8EvBfd
         5zoisViT2mqF1Q8R/CoNFyu5pYtL5Etq5PhLzJeI3K9DY1aMvRZ/cvGfaxpD0bc6T1eF
         RRoyBK/8fr44kdxD6GVFg2xoxpOHNKs/aYD5Op7x/2Onnc92xT2etkhNRrHUwWZw3KVn
         M0Yu5zVeVzLf++ELPjhJv82WHsOpERKjzFecV3qDT/Cw07sAiH2bhrGQpRxvUf/PUKvI
         +tWg==
X-Gm-Message-State: AFq9FYI/JYjkOR6o+TRyqCzMehcOJ8zt/RASoeKhZlk4yOx1gaeFfD/y
	aLJ6+tf+psz3eIkhP2m2NsLBJyiT/mK0hpMUJ8CsGBJ+lUyqv23DRaVDabtFsA==
X-Gm-Gg: AYBFou2KShSW9hUGhu2xwMxwghkDMyQqeniU9oXo9SERo93Mu2DjLP1RxBfPWvsUNcS
	69eD8EnM2hiYyta2MQgDljzzLgbPhf1EZPTOy4G9NqSWLkP6qP3ovZ5tAeVQPDh5LKkreBxNn8l
	svdjmntPYSZzPgPGrqGLFH8o8GaY0XPcLsSR0Kselsnd27nHT3e4b/KddEcYFhlk1sxi/dhIwi5
	SNC8BoHo3enMRRVhkAsIo25eTrFd5nOJbLweADZt3JWyEFBhGeTEKk8prKb4C7a7FNWGCdbupoG
	y4q5YIlDbVWHSCspboifDkHxb7lJ7FhWTvlfGEfKOvxo8QezhKQAFX/dK1qtSG7TL/CKfgKxLvG
	oMzRQ+O1UysBEfnkAH6Vdcv7MWInUrxHcVJQP+PV1H2HH06RMUTxEn1JZT8345aMJa1pw6kQY4N
	VV85xC76CoKn8dMn0sLt2dSVsi/jIIpa1A2B3fj/rLNhLJiF2VjtLPzC6r61VX2d7rnXMNpAlNa
	DuEv6Vxz8yQc7csnmGVAxRMXBxY0w+OepQhTCjpE2WHukSc
X-Received: by 2002:a05:6820:2917:b0:702:dd8d:3176 with SMTP id 006d021491bc7-7035258a3ccmr8019076eaf.2.1792502948978;
        Tue, 20 Oct 2026 06:29:08 -0700 (PDT)
X-Received: from denethor.localdomain ([136.51.44.64])
        by smtp.gmail.com with ESMTPSA id 006d021491bc7-7018f2e0d89sm9973129eaf.6.2026.10.20.06.29.08
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 20 Oct 2026 06:29:08 -0700 (PDT)
X-Cc: ps@pks.im,
	Justin Tobler <jltobler@gmail.com>
X-Mailer: git-send-email 2.56.0.173.gf57c9a7388
X-In-Reply-To: <20261016213716.593278-1-jltobler@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list