{"thread":{"id":"62844","subject":"unlink errors under windows in git pack-refs","startedAt":"2025-01-22T19:09:12Z","lastAt":"2025-01-24T06:36:41Z","messageCount":2,"participants":["Christian Reich","Patrick Steinhardt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"511085","messageId":"d7fd0b1c-98fe-4cc3-b657-c2c3d0bc5c47@t-online.de","threadId":"62844","inReplyTo":null,"subject":"unlink errors under windows in git pack-refs","fromName":"Christian Reich","fromEmail":"zottelbart@t-online.de","sentAt":"2025-01-22T19:01:31Z","receivedAt":"2025-01-22T19:09:12Z","isPatch":false,"sender":{"key":"zottelbart@t-online.de","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n\nI have a git repository cloned which uses reftables.\n\ngit clone --ref-format=reftable https://github.com/eclipse-jgit/jgit.git\n\nA jgit-program (java) is running and sleeping for 100seconds to \ndemonstrate the problem.\n\n         Git git = Git.init().setDirectory(new \nFile(\"c:\\\\temp\\\\jgit\")).call();\n\n         FileRepository repo = (FileRepository) git.getRepository();\n\n         try {\n             Thread.sleep(100000);\n         } catch (InterruptedException e) {\n         }\n         git.close();\n\nWhile the jgit-program is sleeping in git-bash update a ref und pack the \nreftablefiles:\n\ngit update-ref refs/tags/test 939d321faccd12bff4cb13ce6358820297fbc78e\n\ngit pack-refs\n\nWhat did you expect to happen? (Expected behavior)\n\ngit pack-refs should work without messages.\n\nWhat happened instead? (Actual behavior)\n\ngit tries to unlink the reftable-files, but jgit hold windows-system \nlock, so the file can't be unlinked.\nAn answers 'n' for retry causes more asks. After the third try git give up.\n\nUnlink of file \n'C:/temp/jgittest/jgit/.git/reftable/0x000000000002-0x000000000004-50486d0e.ref' \nfailed. Should I try again? (y/n) n\nUnlink of file \n'C:/temp/jgittest/jgit/.git/reftable/0x000000000002-0x000000000004-50486d0e.ref' \nfailed. Should I try again? (y/n) n\nUnlink of file \n'C:/temp/jgittest/jgit/.git/reftable/0x000000000002-0x000000000004-50486d0e.ref' \nfailed. Should I try again? (y/n) n\n\n\nWhat's different between what you expected and what actually happened?\n\nI would expect, that git tries to unlink the files. But if this fails \ngit should ignore this and try to delete the files next time on \npack-files. Its documented in https://git-scm.com/docs/reftable\n\nAnything else you want to add:\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.48.0.rc2.windows.1\ncpu: x86_64\nbuilt from commit: 049f0cf1a5d000f1e24f0e80b79b0d043a8b83b2\nsizeof-long: 4\nsizeof-size_t: 8\nshell-path: D:/git-sdk-64-build-installers/usr/bin/sh\nfeature: fsmonitor--daemon\nlibcurl: 8.11.1\nOpenSSL: OpenSSL 3.2.3 3 Sep 2024\nzlib: 1.3.1\nuname: Windows 10.0 22631\ncompiler info: gnuc: 14.2\nlibc info: no libc information available\n$SHELL (typically, interactive shell): C:\\Program Files\\Git\\usr\\bin\\bash.exe\n\n\n[Enabled Hooks]\ncommit-msg\n\n"},{"id":"511142","messageId":"Z5M08DQCZ_43EIbm@pks.im","threadId":"62844","inReplyTo":"d7fd0b1c-98fe-4cc3-b657-c2c3d0bc5c47@t-online.de","subject":"Re: unlink errors under windows in git pack-refs","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-24T06:36:32Z","receivedAt":"2025-01-24T06:36:41Z","isPatch":false,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Jan 22, 2025 at 08:01:31PM +0100, Christian Reich wrote:\n> What happened instead? (Actual behavior)\n> \n> git tries to unlink the reftable-files, but jgit hold windows-system lock,\n> so the file can't be unlinked.\n> An answers 'n' for retry causes more asks. After the third try git give up.\n> \n> Unlink of file 'C:/temp/jgittest/jgit/.git/reftable/0x000000000002-0x000000000004-50486d0e.ref'\n> failed. Should I try again? (y/n) n\n> Unlink of file 'C:/temp/jgittest/jgit/.git/reftable/0x000000000002-0x000000000004-50486d0e.ref'\n> failed. Should I try again? (y/n) n\n> Unlink of file 'C:/temp/jgittest/jgit/.git/reftable/0x000000000002-0x000000000004-50486d0e.ref'\n> failed. Should I try again? (y/n) n\n> \n> \n> What's different between what you expected and what actually happened?\n> \n> I would expect, that git tries to unlink the files. But if this fails git\n> should ignore this and try to delete the files next time on pack-files. Its\n> documented in https://git-scm.com/docs/reftable\n\nYeah, very true, it is expected that unlinking old reftables may fail,\nand this should be totally benign indeed. In fact, none of the callsites\nof unlink(3p) even check its return value and we just continue to run\nwitih stale files.\n\nThe question comes from `mingw_unlink()`, which we use on Windows\nplatforms:\n\n\twhile (ret == -1 && is_file_in_use_error(GetLastError()) &&\n\t       ask_yes_no_if_possible(\"Unlink of file '%s' failed. \"\n\t\t\t\"Should I try again?\", pathname))\n\t       ret = _wunlink(wpathname);\n\nAs you can see, the loop should immediately exit when you answer 'n',\nand I assume that this even happens. So where do the other asks come\nfrom? One such location is in `reftable_be_pack_refs()`, which calls\n`reftable_stack_clean()`. This function will try to prune any old\ntables which aren't referenced anymore. The other callsite comes from\nreloading the stack, where we again try to unlink now-unreferenced\ntables. All of these calls are benign.\n\nSo the problem is that we use the EBUSY-handling in `mingw_unlink()` in\nthe first place. I'll send a patch in a bit to address this issue.\n\nThanks for the report!\n\nPatrick\n"}]}