Bug 569349 - PackInvalidException when fetch and repack run concurrently
Summary: PackInvalidException when fetch and repack run concurrently
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 5.1.15   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-01 03:50 EST by Petr Hrebejk CLA
Modified: 2020-12-02 04:07 EST (History)
1 user (show)

See Also:


Attachments
Errors on client and server (7.95 KB, text/plain)
2020-12-01 03:50 EST, Petr Hrebejk CLA
no flags Details
Proposed fix (927 bytes, patch)
2020-12-01 03:50 EST, Petr Hrebejk CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Hrebejk CLA 2020-12-01 03:50:18 EST
Created attachment 284930 [details]
Errors on client and server

Hi,

We are running several servers with jGit. We need to run repack from time to time to keep the repos performant. I.e. after push we test how many small packs are in the repo and when a threshold is reached we run the repack.
After upgrading jGit version we've found that if someone does the clone at the time repack is running the clone sometimes (not always) fails because the repack removes .pack file used by the clone. Server exception and client error attached.

I've tracked down the cause and it seems to be introduced between jGit 5.2 (which we upgraded from) and 5.3 and being caused by this commit: Move throw of PackInvalidException outside the catch - https://github.com/…400

The problem is that when the throw was inside of the try block the last catch block catched the exception and called openFailed(false) method. It is true that it called it with invalidate = false, which is wrong. The real problem though is that with the throw outside of the try block the openFail is not called at all and the fields activeWindows and activeCopyRawData are not set to 0. Which affects the later called tests like: if (++activeCopyRawData == 1 && activeWindows == 0).

The fix for this is relatively simple keeping the throw outside of a the try block and still having the invalid field set to true. See the attached patch (against current master). I did exhaustive testing of the change running concurrent clones and pushes indefinitely and with the patch applied it never fails where without it takes relatively short to get the error. However I'm not an expert in the jGit code and I may well be wrong about how to fix this.
Comment 1 Petr Hrebejk CLA 2020-12-01 03:50:42 EST
Created attachment 284931 [details]
Proposed fix
Comment 3 Matthias Sohn CLA 2020-12-02 04:07:48 EST
thanks for the fix :-)