Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlink of file XXX failed. Should I try again? #500

Closed
gpakosz opened this issue Oct 21, 2015 · 22 comments
Closed

Unlink of file XXX failed. Should I try again? #500

gpakosz opened this issue Oct 21, 2015 · 22 comments
Assignees

Comments

@gpakosz
Copy link

gpakosz commented Oct 21, 2015

Hello,

Sometimes, after a e.g. git fetch, Git decides to auto GC a repository. In the process, it fails to remove .pack and .idx files. Likely, those files are locked.

Git can ask the question for more than 50 times depending on the number of unreachable commits there are following branch deletion and remotes pruning. When Git starts to complain, either you answer "no" repeatedly until the auto GC ends, or you have to CTRL-C. Ultimately, invoking git gc manually removes most of the pack files

@dscho
Copy link
Member

dscho commented Oct 21, 2015

@gpakosz hmm. Do you think you can come up with a reproducible example? Something like a shell script that creates a small repository, clones it, then sets gc thresholds ridiculously low, adds more commits and then fetches them?

@kgybels
Copy link

kgybels commented Oct 21, 2015

@dscho Something like this?

KGybels@PC-KG MINGW64 /c/git/bug
$ git --version
git version 2.6.1.windows.1

KGybels@PC-KG MINGW64 /c/git/bug
$ ls
steps.sh*

KGybels@PC-KG MINGW64 /c/git/bug
$ cat steps.sh
#!/bin/bash

git init origin
cd origin
touch test1.txt
git add test1.txt
git commit -m v1
originpath=`pwd`
cd ..
git clone file://$originpath clone
cd origin
touch test2.txt
git add test2.txt
git commit -m v2
cd ../clone
git config gc.autoPackLimit 1
git fetch

KGybels@PC-KG MINGW64 /c/git/bug
$ ./steps.sh
Initialized empty Git repository in C:/git/bug/origin/.git/
[master (root-commit) 775d4c6] v1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1.txt
Cloning into 'clone'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
[master 25c50c7] v2
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test2.txt
remote: Counting objects: 2, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From file:///c/git/bug/origin
   775d4c6..25c50c7  master     -> origin/master
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), done.
Total 5 (delta 0), reused 3 (delta 0)
Unlink of file '.git/objects/pack/pack-97e500b3cd7317acb865c29bb44d66886116c51a.pack' failed. Should I try again? (y/n) n
Unlink of file '.git/objects/pack/pack-97e500b3cd7317acb865c29bb44d66886116c51a.idx' failed. Should I try again? (y/n) n

KGybels@PC-KG MINGW64 /c/git/bug
$

@dscho
Copy link
Member

dscho commented Oct 22, 2015

@kgybels very nice!

@dscho dscho self-assigned this Oct 22, 2015
@gpakosz
Copy link
Author

gpakosz commented Oct 22, 2015

Oh nice @kgybels, I added the task in my TODO but I'm thankful you took over. 👍

@cs96and
Copy link

cs96and commented Jan 13, 2016

I sometimes have this problem and I believe it is related to TortoiseGit's TGitCache.exe having those files open.

@gpakosz
Copy link
Author

gpakosz commented Jan 13, 2016

It's definitely not related to TortoiseGit. As you can see above, @kgybels provided a script that reproduces the problem. It's totally unrelated to any Git frontend

dscho added a commit to dscho/git that referenced this issue Jan 13, 2016
Before auto-gc'ing, we need to make sure that the pack files are
released in case they need to be repacked and garbage-collected.

This fixes git-for-windows#500

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member

dscho commented Jan 13, 2016

@gpakosz sorry for the long delay! In the meantime, I had taken care of #446 which made this fix substantially quicker, though.

@cs96and
Copy link

cs96and commented Jan 13, 2016

@gpakosz But is TortoiseGit installed? It can have those files locked even though you are currently using git on the command line.

@dscho
Copy link
Member

dscho commented Jan 13, 2016

@cs96and if TortoiseGit, or for that matter, any software locks pack files, the "Unlink of file XXX failed." is actually the proper response and there is no bug in Git.

The bug at hand is caused by Git itself keeping locks on the files that it wants to garbage-collect. And that bug is what I just fixed.

@linquize
Copy link

Not just TortoiseGit, Atom text editor also sometimes locks the packfile too.

@dscho
Copy link
Member

dscho commented Jan 13, 2016

Well, Atom text editor is included in "any software", no?

Apart from that, what business does Atom text editor have to lock pack files? Seriously.

@kostix
Copy link

kostix commented Jan 13, 2016

@dscho, because it's more of an IDE (written in HTML5 on top of node.js and craploads of other bits of what is considered "hot stuff" these days) than a text editor. IDEs strive to provide VCS integration. Supposedly they're using libgit2 or something. Since it's done by github folks I'd not be surprised to actually find pieces of GfW inside (as it's AFAIK true for that piece of software named "Github for Windows").

All in all, failing to lock a locked file is for sure the only sensible way to go IMO.

dscho added a commit to dscho/git that referenced this issue Jan 13, 2016
Before auto-gc'ing, we need to make sure that the pack files are
released in case they need to be repacked and garbage-collected.

This fixes git-for-windows#500

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@gpakosz
Copy link
Author

gpakosz commented Jan 13, 2016

@dscho no worry, thanks for taking care of fixing it, much appreciated

gitster pushed a commit to git/git that referenced this issue Jan 13, 2016
Before auto-gc'ing, we need to make sure that the pack files are
released in case they need to be repacked and garbage-collected.

This fixes git-for-windows#500

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
@dscho
Copy link
Member

dscho commented Jan 27, 2016

This hit upstream's master, so it will be fixed in the next release of Git for Windows.

@dscho dscho closed this as completed Jan 27, 2016
@gpakosz
Copy link
Author

gpakosz commented Jan 27, 2016

Thank you @kgybels, @dscho and @gitster. This one has been nagging me literally for years.

@dscho
Copy link
Member

dscho commented Jan 27, 2016

@gpakosz note that in Open Source, you can always work on your own itches... 😃

@gpakosz
Copy link
Author

gpakosz commented Jan 27, 2016

@dscho That's true. I confess I never really tried to climb the learning curve of being able to compile and debug Git For Windows. And the first years it was all too easy to blame NTFS ;)

@dscho
Copy link
Member

dscho commented Jan 27, 2016

It's always easy to blame NTFS. And for the record: when I started working on Git, I also had no idea how to compile and debug Git for Windows...

dscho added a commit that referenced this issue Jan 28, 2016
Before auto-gc'ing, we need to make sure that the pack files are
released in case they need to be repacked and garbage-collected.

This fixes #500

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dscho added a commit that referenced this issue Jan 28, 2016
This fixes #500

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@kgybels
Copy link

kgybels commented Jun 30, 2018

There is a regression from 2.17.1.windows.2 to 2.18.0.windows.1. I already send a patch to the Git mailing list.

@dscho
Copy link
Member

dscho commented Jul 1, 2018

I already send a patch to the Git mailing list.

Thanks! Can you let me know when it gets into next so I can cherry-pick? (I would like to avoid cherry-picking a commit that I later have to revert in order to cherry-pick a newer iteration... maintenance... or do you want me to pick it as a quick fix already?)

gitster pushed a commit to git/git that referenced this issue Jul 6, 2018
Teach gc --auto to clear the repository before auto packing it to
prevent failures when removing files on Windows.

Also teach the test 'fetching with auto-gc does not lock up' to complain
when it is no longer triggering an auto packing of the repository.

Fixes git-for-windows#500

Signed-off-by: Kim Gybels <kgybels@infogroep.be>
Helped-by: Duy Nguyen <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitster pushed a commit to git/git that referenced this issue Jul 9, 2018
Teach gc --auto to release pack files before auto packing the repository
to prevent failures when removing them.

Also teach the test 'fetching with auto-gc does not lock up' to complain
when it is no longer triggering an auto packing of the repository.

Fixes git-for-windows#500

Signed-off-by: Kim Gybels <kgybels@infogroep.be>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
@kgybels
Copy link

kgybels commented Jul 26, 2018

@dscho Can you let me know when it gets into next so I can cherry-pick?

Change is merged to next on 2018-07-24 at 71c05d2. It will also be merged to master.

@dscho
Copy link
Member

dscho commented Jul 27, 2018

I opened a PR. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants