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

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

From
Justin Tobler <jltobler@gmail.com>
Date
Oct 20, 2026, 13:28 UTC
Message-ID
<20261020132900.1208343-1-jltobler@gmail.com>
In-Reply-To
<20261016213716.593278-1-jltobler@gmail.com>
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
Previous: Patrick SteinhardtNext: Justin Tobler
Message 19 of 40 in “object-file: fix ".keep" lockfile ownership in ODB transactions”
  1. 0/3 object-file: fix ".keep" lockfile ownership in ODB transactionsJustin Tobler, Oct 16, 2026
  2. 1/3 pack-write: lift and expose index-pack report parsingJustin Tobler, Oct 16, 2026
  3. Patrick SteinhardtOct 16, 2026
  4. Justin ToblerOct 16, 2026
  5. 2/3 object-file: explicitly write ".keep" lockfileJustin Tobler, Oct 16, 2026
  6. Patrick SteinhardtOct 16, 2026
  7. Justin ToblerOct 16, 2026
  8. 3/3 object-file: write ".keep" lockfiles during transaction commitJustin Tobler, Oct 16, 2026
  9. Patrick SteinhardtOct 16, 2026
  10. Justin ToblerOct 16, 2026
  11. 0/4 object-file: fix ".keep" lockfile ownership in ODB transactionsJustin Tobler, Oct 16, 2026
  12. 1/4 pack-write: make index-pack output comment hash agnosticJustin Tobler, Oct 16, 2026
  13. 2/4 pack-write: lift and expose index-pack report parsingJustin Tobler, Oct 16, 2026
  14. 3/4 object-file: explicitly write ".keep" lockfileJustin Tobler, Oct 16, 2026
  15. Patrick SteinhardtOct 19, 2026
  16. Justin ToblerOct 19, 2026
  17. 4/4 object-file: write ".keep" lockfiles during transaction commitJustin Tobler, Oct 16, 2026
  18. Patrick SteinhardtOct 19, 2026
  19. 0/4 object-file: fix ".keep" lockfile ownership in ODB transactionsJustin Tobler, Oct 20, 2026
  20. 1/4 pack-write: make index-pack output comment hash agnosticJustin Tobler, Oct 20, 2026
  21. 2/4 pack-write: lift and expose index-pack report parsingJustin Tobler, Oct 20, 2026
  22. 3/4 object-file: explicitly write ".keep" lockfileJustin Tobler, Oct 20, 2026
  23. Patrick SteinhardtOct 20, 2026
  24. Justin ToblerOct 20, 2026
  25. Junio C HamanoOct 21, 2026
  26. 4/4 object-file: write ".keep" lockfiles during transaction commitJustin Tobler, Oct 20, 2026
  27. Patrick SteinhardtOct 20, 2026
  28. 0/4 object-file: fix ".keep" lockfile ownership in ODB transactionsJustin Tobler, Oct 21, 2026
  29. 1/4 pack-write: make index-pack output comment hash agnosticJustin Tobler, Oct 21, 2026
  30. Karthik NayakOct 26, 2026
  31. Justin ToblerOct 26, 2026
  32. 2/4 pack-write: lift and expose index-pack report parsingJustin Tobler, Oct 21, 2026
  33. 3/4 object-file: explicitly write ".keep" lockfileJustin Tobler, Oct 21, 2026
  34. Karthik NayakOct 26, 2026
  35. Justin ToblerOct 27, 2026
  36. Justin ToblerOct 27, 2026
  37. Karthik NayakOct 26, 2026
  38. 4/4 object-file: write ".keep" lockfiles during transaction commitJustin Tobler, Oct 21, 2026
  39. Karthik NayakOct 26, 2026
  40. Patrick SteinhardtOct 22, 2026

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.