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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



### 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 
```





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux