Bug 582379 - Stale packed refs lock file causes all writes to fail
Summary: Stale packed refs lock file causes all writes to fail
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.13   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-06 15:41 EDT by Marcin Czech CLA
Modified: 2023-11-17 21:30 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcin Czech CLA 2023-09-06 15:41:58 EDT
When new pack file creation fails during the packed refs file updating lock file is not removed. When this happens all following write operations are failing because of the LOCK_FAILURE. Currently only way to resolve the issue is to manually remove the lock file from the repository.

JGit should recognise stale lock file for packed refs file and remove it.
Comment 1 Matthias Sohn CLA 2023-09-06 16:55:38 EDT
(In reply to Marcin Czech from comment #0)
> When new pack file creation fails during the packed refs file updating lock
> file is not removed.

- How is creation of a pack file related to packed-refs ? Which command or API was run to update/create packed-refs ?
- Which lock file was not removed ?
- How did this fail ?
  - with an exception ? If yes, please provide a stacktrace
  - process crashed or was terminated forcefully ?
- did you try using the latest release ?

> When this happens all following write operations are
> failing because of the LOCK_FAILURE. Currently only way to resolve the issue
> is to manually remove the lock file from the repository.
> 
> JGit should recognise stale lock file for packed refs file and remove it.
Comment 2 Matthias Sohn CLA 2023-09-07 20:52:24 EDT
Here is a fix 
https://git.eclipse.org/r/c/jgit/jgit/+/204213
assuming you meant that if the JVM shuts down gracefully during repacking of packed-refs the file lock isn't removed.
Comment 3 Marcin Czech CLA 2023-09-08 02:55:24 EDT
> - How is creation of a pack file related to packed-refs ? Which command or
> API was run to update/create packed-refs ?
> - Which lock file was not removed ?
> - How did this fail ?
>   - with an exception ? If yes, please provide a stacktrace
>   - process crashed or was terminated forcefully ?
> - did you try using the latest release ?

> - How is creation of a pack file related to packed-refs ?
If I understand correctly during the write operation packed-refs file is locked and updated(I believe new packed-refs file is created and then swapped)

> - Which lock file was not removed ?
packed-refs lock file

> - How did this fail ?
System was under the heavy load and thread which was executing the write operation failed with out of memory.

>- process crashed or was terminated forcefully ?
crashed
Comment 4 Marcin Czech CLA 2023-09-08 02:59:39 EDT
(In reply to Matthias Sohn from comment #2)
> Here is a fix 
> https://git.eclipse.org/r/c/jgit/jgit/+/204213
> assuming you meant that if the JVM shuts down gracefully during repacking of
> packed-refs the file lock isn't removed.

Thank you for the pointer to the fix. This will definitely help when we do graceful shutdown. In our case one of the Gerrit threads failed due to heavy load on the system and it left the lock file so all other operation were blocked.

Currently we have a cron job which is checking if there is a packed-refs lock file older than x.

Looks like it's a common problem:
https://groups.google.com/g/repo-discuss/c/82BOvCYQ4m8/m/WkpWwIp3AwAJ
Comment 5 Matthias Sohn CLA 2023-09-12 17:12:49 EDT
(In reply to Matthias Sohn from comment #2)
> Here is a fix 
> https://git.eclipse.org/r/c/jgit/jgit/+/204213

the fix was merged as d4d6c2b5af9b984ae824fb0073e1b368b39b1aa4
Comment 6 Luca Milanesio CLA 2023-11-17 21:30:47 EST
The problem keeps on happening on Gerrit.

In the meantime I've created a simple Groovy plugin that can check for packed-refs.lock staleness, log the issue and remove the lock automatically.

See https://gerrit-review.googlesource.com/c/plugins/scripts/+/393337