🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #560

Re: [PATCH 2/2] commit: lock index before reading

#560
From: Jun Wu
Date: Thu, 15 Oct 2026 00:19
35 lines
9488 bytes
Hi Peff,

On Wed, 14 Oct 2026 06:04:32 -0400, Jeff King wrote:
> I do think your patch fixes the problem. But we probably want to discuss
> that in the commit message as a motivation (and likewise, discuss the
> fact that we may be holding the lock for longer).

Will do in v2: describe the race as motivation, and mention the longer hold
trade-off.

I'd like to note 'commit' is just one command with the read/lock order issue.
There are many others, like: reset, rebase, stash, am, merge, etc.
Some are easy to fix, some seem tricky (e.g. merge).

Do you think that I should fix all order issues before adding the timeout?

Note Patch 1 alone does not hurt - if a command has the read/lock order issue
and is therefore racy, then the timeout feature is automatically disabled
(by the 'initialized' check) so the racy command behaves exactly the same as
before, not worse.

My plan is to add the timeout support first, then incrementally fix order
issues, starting from the easy/more common ones (e.g. commit).

> There's probably some kind of hybrid world where we optimistically read
> without the lock, then take the lock, and then check (cheaply-ish) that
> the index didn't change since what we read. But I don't think we do that
> in this code path.

For reference, 'status' is such an example, although its write is optional.
'add -i' could be another example - it avoids locking when waiting for user
input, although it lacks the "didn't change" check right now.

-Jun
Technical Details
Message-ID: <20261015001938.2092523-1-quark.zju@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-72075-linux-kernel-git=dewy.ru
References: <20261013172315.2997446-1-quark.zju@gmail.com> <20261013172315.2997446-3-quark.zju@gmail.com> <20261014100432.GB1344504@coredump.intra.peff.net>

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-72075-linux-kernel-git=dewy.ru
From: quark.zju@gmail.com (Jun Wu)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH 2/2] commit: lock index before reading
Date: Wed, 14 Oct 2026 17:19:37 -0700
Organization: Usenet Network
Message-ID: <20261015001938.2092523-1-quark.zju@gmail.com>
References: <20261013172315.2997446-1-quark.zju@gmail.com> <20261013172315.2997446-3-quark.zju@gmail.com> <20261014100432.GB1344504@coredump.intra.peff.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2416683"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:fcYyN4VKL9ragbC8DVWR6RJdL74= sha256:g2nzxsrlREjjAa9XIScVt+3+jHMjK3DOa9efieKI834=
	sha1:eHpilW7O6AeHoDj0Mq3outWTxdY= sha256:jr0pi8C6+icrnsEOMS6iC8ELskQgi5/SN6xh1vfhNjQ=
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 44206110203; Thu, 15 Oct 2026 03:22:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.748
X-Spam-Status: No, score=-0.748 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, SPF_HELO_NONE=0.001, SPF_PASS=-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 cfttJNYMImeY;
	Thu, 15 Oct 2026 03:22:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72075-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 99DB9110182; Thu, 15 Oct 2026 03:22:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id D91983DC4D; Thu, 15 Oct 2026 00:19:47 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B850B1CAA78;
	Thu, 15 Oct 2026 00:19:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fpNuA1G3"
X-Received: from mail-dl1-f44.google.com (mail-dl1-f44.google.com [74.125.82.44])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A07A146A66
	for <git@vger.kernel.org>; Thu, 15 Oct 2026 00:19:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.44
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792023584; cv=none; b=JtNfNnzO44DFfhA/JrbVrF3mSXXvG6xz2/7o6NqQAINuOxz/9Zq84G4x3YK0fwnD3Y/r85udqKxTHutm0o1e6WuIPv2vq3l5OMNeAU6g4Bma0bWqDSYKOsaJosHZ6Hz6uMx9t5vQNNl/JutiDagX0If00l5xxi5J4slVTI/dfGE=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792023584; c=relaxed/simple;
	bh=Wrz3/r0L5AiZ/0Cc4iMDWbFGxwRFiGkpoiJCTAZiCXw=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=MIcDcaQb6XtbIcrfkURG1sG4Os3E+/ffdTJ9T956acQY5fgUN/+J7DfpTnZz5aLOBx9zyf3/pBt52cMfw6jcWSBeA4bxDnIrksv2LM8TM5VrPHvKUBEy+4NQv73ODApnJ99MB6xUc0Z6fKV0uqC49qV46YFEbtcA32wnsX21/M8=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fpNuA1G3; arc=none smtp.client-ip=74.125.82.44
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-dl1-f44.google.com with SMTP id a92af1059eb24-170135e43c7so2240545c88.0
        for <git@vger.kernel.org>; Wed, 14 Oct 2026 17:19:43 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792023582; x=1792628382; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type: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=Wrz3/r0L5AiZ/0Cc4iMDWbFGxwRFiGkpoiJCTAZiCXw=;
        b=fpNuA1G3YZ88OEVuDzkmxuV4UD8P680eoJGS6zUTvk9yJcY4KjjZbtdUvN6BOt36H/
         o87kb7GoY93rgIu6Mgwx2f0P8iADyzPP4n/trbIcmEwMPQl56WRR9V4Flz77bD/owATx
         o7Ou8VR8z+HBWPBrO9uC10Vo2JJq/xaQ+0FeJhZ0BgWpIEk2S1wKk9NcCuz10K/koxEC
         /X9XBjJTuG6XvQWIBTXKB7Zyp+adeVqEvH+E9RDdPVtrRSmyQMSIcdd5aPp5sBXBTN89
         oS6fD0zP1QhbtKjAPP3Fb2DczZfyWSGJ6rTnU6LtHysqq8OvVx8zkhthwEU6EaiggBaH
         2YkQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792023582; x=1792628382;
        h=content-transfer-encoding:content-type: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=Wrz3/r0L5AiZ/0Cc4iMDWbFGxwRFiGkpoiJCTAZiCXw=;
        b=vM0cpXyJNc7AEjS4P2G8itn2gExrtzI+TIS0zuQOdINBJuuHsPrOphzK8M4Bsp2LEx
         ehvKji1RJL7Y/y9t6XS/iFx8mdXY2Tckv3HAZiWRHES1Zafk/UED4QgKDfKqZ7Vfm1tT
         uLGmOKxnxz37KPH53uTqHMW3kSSfFZ0sEBkMP4UH3ut5Qtiox+2MyX6mCfr5A29DA3G2
         CM2hMdSj/OhYKh8puvhuF3XhxTGZbjQa4c8ZNSj1vJXbjHNvg8fnPqjn9/pLd40HEtKZ
         eCcMPba/XbVNpK3D4ffl06oLZP/lAh9t/koZICDZszpX0yWhqcY2Jj4RkW/tNrk9tjQU
         ux9A==
X-Gm-Message-State: AFq9FYIOikeXYUR3V4mOhmhrMGzy6Oenu+ErV6OmiYrW4l/VlY/aKnRm
	MtwgsTHeP0H1XU6VAM9XQcKIxqiA/SwjBze4yss56deHF/+z+Q2jE66v
X-Gm-Gg: AYBFou2HFDVLedLgX8W5V1t5FDm2tECzcqc6ARSqbD0K5e03pDku6LMVPViJ2Sk+WMB
	0xjJrme2niC3lEPK4szg+/sFq+1jpANBRYWpoGAbjo2BwOj7zVQ7cMZnMmjE7spOUgwh0WtIdl9
	wvcge7CQAt+USNPQI/Msj/6cdlxpR/A20Lvxh12WezgdSO8viAZ7TB+z1RzM3Xc/xBAuQd/vP3J
	AxdTpkpENgPtANBQ5F8qfxB2NXWARFqqK64RsbeDhLY/73aE6I/OYBbelMZ31D3OpsJCoQve/TG
	FiCh+eoy9KBUzycr+Ge1L5v3vxR2Aj6wXd+luFcrrek2kuFu1crmji1Ud/RsAadmvcuROcisk/E
	QAHzLb+M0KvNqgojjM5OxQpXNcI8qBdjIazm6Gui2wXOic91ellrPFxnX6abBqSZsr1+cApYF3l
	Q2tWJD+wM7eCgjDv4PsZBsA8Vip8caHbauy6CJ09BMFZ6VnbgYCWrBhHe6HL+GscGIj958RD5Kn
	ovSNHnwbIkO0sy0x1954KYPhQ7jGFUAbdT5ORIYhLpUeBIXMGRcu8JKU38f1v9joARVtrxNRTjB
X-Received: by 2002:a05:7022:5f07:b0:168:6ad8:e8ae with SMTP id a92af1059eb24-16a6187f492mr22566579c88.11.1792023582302;
        Wed, 14 Oct 2026 17:19:42 -0700 (PDT)
X-Received: from quark-fedora-PF5F60VQ (162-199-88-188.lightspeed.sntcca.sbcglobal.net. [162.199.88.188])
        by smtp.gmail.com with ESMTPSA id a92af1059eb24-169a442956asm64288057c88.16.2026.10.14.17.19.41
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Wed, 14 Oct 2026 17:19:41 -0700 (PDT)
X-Cc: git@vger.kernel.org,
	gitster@pobox.com,
	ps@pks.im,
	Jun Wu <quark@meta.com>
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20261014100432.GB1344504@coredump.intra.peff.net>
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>