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

[Bug] Git ReadOnly Temp Packfile Causes "Bad file descriptor" And -13 Access Error With NFSv4

From
MBMaloney, Bryan <bryanhm@amazon.com>
Date
Feb 10, 2025, 15:56 UTC
Message-ID
<17DE42DF-D2A3-4E25-9198-5AF3CA516E35@amazon.com>
In-Reply-To
<18589D54-5E7F-434D-A890-B39102ECB293@amazon.com>
### Error
Kernel logs:
```
NFSv4: state recovery failed for open file pack/tmp_pack_aR0Mu3, error = -13
```
Git clone output:
```
fatal: write error: Bad file descriptor, 137.31 MiB | 45.77 MiB/s
fatal: fetch-pack: invalid index-pack output
```
### Context
The following error is seen when running git clone over NFSv4 and a failover, or server restart, occurs:
```
NFSv4: state recovery failed for open file pack/tmp_pack_aR0Mu3, error = -13
```
This error is an access denied error that happens when you try to open a file with insufficient permissions. In this case the file being opened is a read only file and it is attempted to be opened with write access.
Git opens/creates this file with the O_RDWR flag but then applies read only permissions to it, 0444. Since the permissions are changed after the file is opened, the file handle works fine. However if the file was attempted to be re-opened with that same file handle we would see a -13 error. This is what we see following a failover in NFSv4. When clients reclaim their open files, the NFS server re-evaluates the file access.
```
    int mode = 0444;
    git_path_buf(temp_filename, "objects/%s", pattern);
    fd = git_mkstemp_mode(temp_filename->buf, mode);
```
- https://github.com/git/git/blob/master/object-file.c#L478
```
        fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, mode);
```
- https://github.com/git/git/blob/master/wrapper.c#L491
This is an issue for active/passive HA file servers. Since NFSv4 evaluates file permissions at the time of opening a file, this FD will always get an access denied error if a failover occurs during git clone.
### Reproducer

On the client, mount the NFS share with NFSv4 and run git clone using the NFS mount as the target directory. ``` root@ip-10-0-85-241:/home/ubuntu# mount -t nfs -o nfsvers=4.2,nconnect=16 10.0.66.58:/share /nfsmnt root@ip-10-0-85-241:/home/ubuntu# mkdir -p /nfsmnt/react

root@ip-10-0-85-241:/home/ubuntu# git clone -v https://github.com/facebook/react.git /nfsmnt/react Cloning into '/nfsmnt/react'... remote: Enumerating objects: 356868, done. remote: Counting objects: 100% (543/543), done. remote: Compressing objects: 100% (256/256), done. fatal: write error: Bad file descriptor, 137.31 MiB | 45.77 MiB/s fatal: fetch-pack: invalid index-pack output

root@ip-10-0-85-241:/home/ubuntu# grep NFS /var/log/kern.log 2025-02-07T21:54:42.562725+00:00 ip-10-0-85-241 kernel: NFSv4: state recovery failed for open file pack/tmp_pack_LkbrKa, error = -13 ```

On the server, restart NFS server client is on the “Receiving objects” step of git clone. ``` # systemctl restart nfs-server.service  ```

Next: brian m. carlson
Message 1 of 4 in “[Bug] Git ReadOnly Temp Packfile Causes "Bad file descriptor" And -13 Access Error With NFSv4”
  1. Maloney, BryanFeb 10, 2025
  2. brian m. carlsonFeb 10, 2025
  3. Jeff KingFeb 11, 2025
  4. brian m. carlsonFeb 11, 2025

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.