File descriptor leak and strange behavior
blackgnezdo opened this issue · comments
I noticed my alacritty is exhausting its fds. The scenario is:
- open a new window
- run
ls; fstat -p $alacritty-pid
a few times - watch the number of fds go up eventually hitting the process limit of 512
The output of fstat at this point becomes:
% fstat -p 66953
USER CMD PID FD MOUNT INUM MODE R/W SZ|DV
greg alacritty 66953 text /usr/local 233303 -rwxr-xr-x r 5005488
greg alacritty 66953 wd /home 4177920 drwxr-xr-x r 2048
greg alacritty 66953 0 / 104852 crw-rw-rw- r null
greg alacritty 66953 1 /home 4177929 -rw------- w 225260
greg alacritty 66953 2 /home 4177929 -rw------- w 225260
greg alacritty 66953 3* unix stream 0x0
greg alacritty 66953 4 kqueue 0x0 0 state: W
greg alacritty 66953 5 pipe 0x0 state:
greg alacritty 66953 6 pipe 0x0 state:
greg alacritty 66953 7 kqueue 0x0 0 state:
greg alacritty 66953 8 kqueue 0x0 0 state: W
greg alacritty 66953 9 pipe 0x0 state:
greg alacritty 66953 10 pipe 0x0 state:
greg alacritty 66953 11* unix stream 0x0 /tmp/Alacritty-:0-66953.sock
greg alacritty 66953 12 /home 4177920 drwxr-xr-x re 2048
greg alacritty 66953 13* unix stream 0x0
greg alacritty 66953 14* unix stream 0x0
greg alacritty 66953 16* unix stream 0x0
greg alacritty 66953 17* unix stream 0x0
greg alacritty 66953 18 clone 103696 crw------- rwep dri/card0
greg alacritty 66953 19 clone 103696 crw------- rwep dri/card0
greg alacritty 66953 20 clone 103696 crw------- rwep dri/card0
greg alacritty 66953 21 clone 103696 crw------- rwep dri/card0
greg alacritty 66953 22* unix stream 0x0
greg alacritty 66953 23 / 104181 crw-rw-rw- rw ptyp1
greg alacritty 66953 24 kqueue 0x0 0 state: W
greg alacritty 66953 25* unix stream 0x0
greg alacritty 66953 26 pipe 0x0 state:
greg alacritty 66953 27 pipe 0x0 state:
greg alacritty 66953 28 /home 4177923 -rw-r--r-- re 87
greg alacritty 66953 29 /home 4177921 drwx------ re 1024
...
greg alacritty 66953 506 /home 4282383 drwx------ re 4096
greg alacritty 66953 507 /home 4282496 -rw-r--r-- re 90
greg alacritty 66953 508 /home 4284280 -rw-r--r-- re 178
greg alacritty 66953 509 /home 4288090 -rw-r--r-- re 0
greg alacritty 66953 510 /home 4288232 -rw-r--r-- re 80
greg alacritty 66953 511 /home 4288632 -rw-r--r-- re 70
When running under ktrace I see inexplicable open of a large number of files I don't expect the terminal to
have any interest in:
$ grep -B2 'RET open' /tmp/d
...
--
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles"
88975 alacritty RET open 498/0x1f2
--
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git"
88975 alacritty RET open 505/0x1f9
--
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty RET open -1 errno 24 Too many open files
--
88975 alacritty CALL open(0x24ae399428,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg"
88975 alacritty RET open 69/0x45
--
88975 alacritty RET futex 0
88975 alacritty NAMI "/home/greg"
88975 alacritty RET open 69/0x45
--
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/pkgs"
88975 alacritty RET open 69/0x45
--
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/pkgs"
88975 alacritty RET open 505/0x1f9
--
88975 alacritty RET stat 0
88975 alacritty CALL open(0x24ae399428,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty RET open -1 errno 24 Too many open files
--
88975 alacritty RET stat 0
88975 alacritty CALL open(0x24ae399428,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty RET open -1 errno 24 Too many open files
--
System
OS: OpenBSD 7.5
Version: alacritty 0.12.3
Linux/BSD: X11
Are you suggesting that fstat
itself is causing the used file descriptors to increase? Also have you tried a different shell?
fstat
seems irrelevant. ls -l
seems to be a good way to trigger an fd opening spree.
I just tried /bin/ksh
and /usr/local/bin/bash
which produce different behaviors compared to my default zsh
. I'm still confused though. How can the choice of shell affect the FDs opened by the alacritty
process?
Here's a longer fragment of ktrace
which hopefully can help identify the code where this activity originates. It doesn't make much sense as the files get open and then ignored:
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/ef"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236416, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004196, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409390<"Dec 12 11:29:50 2023">.162395412, ctime=1702409390<"Dec 12 11:29:50 2023">.162395412, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/ef"
88975 alacritty RET open 411/0x19b
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 192/0xc0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/ef/3d761bee4d487e34599bb0bd61eb2d49db7889"
88975 alacritty RET open 412/0x19c
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/ef/446424de76410dff754f06df3f4c454b77b120"
88975 alacritty RET open 413/0x19d
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/66"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236418, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004198, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409291<"Dec 12 11:28:11 2023">.002396657, ctime=1702409291<"Dec 12 11:28:11 2023">.002396657, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/66"
88975 alacritty RET open 414/0x19e
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 128/0x80
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/66/c95e430b3a3ac6f40fc94860f0ab89e295b9cf"
88975 alacritty RET open 415/0x19f
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/af"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236420, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004200, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409291<"Dec 12 11:28:11 2023">.002396657, ctime=1702409291<"Dec 12 11:28:11 2023">.002396657, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/af"
88975 alacritty RET open 416/0x1a0
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 128/0x80
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/af/e425f8c2b53b5cde2706717933336f1491b07b"
88975 alacritty RET open 417/0x1a1
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/70"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236422, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004202, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409291<"Dec 12 11:28:11 2023">.002396657, ctime=1702409291<"Dec 12 11:28:11 2023">.002396657, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/70"
88975 alacritty RET open 418/0x1a2
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 128/0x80
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/70/e2fd89baad8401c3a2f102ab6190ad4589a5e9"
88975 alacritty RET open 419/0x1a3
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/2f"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236424, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004204, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1706743545<"Jan 31 15:25:45 2024">.967347103, ctime=1706743545<"Jan 31 15:25:45 2024">.967347103, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/2f"
88975 alacritty RET open 420/0x1a4
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 192/0xc0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/2f/bed18a3c79a6bb2cdf356298a39ba3ae5ccf43"
88975 alacritty RET open 421/0x1a5
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/2f/b8ecf9021351d951468d6ed75e74a12849a67a"
88975 alacritty RET open 422/0x1a6
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/23"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236426, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004206, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409291<"Dec 12 11:28:11 2023">.012395780, ctime=1702409291<"Dec 12 11:28:11 2023">.012395780, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/23"
88975 alacritty RET open 423/0x1a7
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 128/0x80
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/23/b788279bf8f54894bdc564f44a16c6a334e300"
88975 alacritty RET open 424/0x1a8
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/cb"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236431, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004211, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409291<"Dec 12 11:28:11 2023">.012395780, ctime=1702409291<"Dec 12 11:28:11 2023">.012395780, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/cb"
88975 alacritty RET open 425/0x1a9
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 128/0x80
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/cb/8c035df4f95a526736164ba1de0ab55574ab61"
88975 alacritty RET open 426/0x1aa
88975 alacritty CALL getdents(101,0x256f73a000,0x20000)
88975 alacritty RET getdents 0
88975 alacritty CALL close(101)
88975 alacritty RET close 0
88975 alacritty CALL open(0x24ae398b78,0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/e9"
88975 alacritty RET open 101/0x65
88975 alacritty CALL fstat(101,0x24ae398a98)
88975 alacritty STRU struct stat { dev=1051, ino=4236433, mode=drwxr-xr-x , nlink=2, uid=1000<"greg">, gid=1000<"greg">, rdev=17004213, atime=1715810864<"May 15 15:07:44 2024">.731031351, mtime=1702409291<"Dec 12 11:28:11 2023">.012395780, ctime=1702409291<"Dec 12 11:28:11 2023">.012395780, size=512, blocks=8, blksize=32768, flags=0x0, gen=0x0 }
88975 alacritty RET fstat 0
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/e9"
88975 alacritty RET open 427/0x1ab
88975 alacritty CALL getdents(101,0x24bd14f000,0x20000)
88975 alacritty RET getdents 128/0x80
88975 alacritty CALL open(0x24ae399038,0x10000<O_RDONLY|O_CLOEXEC>)
88975 alacritty NAMI "/home/greg/dotfiles/.git/objects/e9/e67cf176b772fb15c0b503af08869ecbdffa2d"
88975 alacritty RET open 428/0x1ac
I'm still confused though. How can the choice of shell affect the FDs opened by the alacritty process?
Alacritty is responsible for spawning the shell, so the shell is going to be its child. I know that strace
requires passing -f
for inspecting children but maybe ktrace
does so by default?
So far it doesn't actually look like an Alacritty issue, if you have any questions or other details feel free to ask.
I installed the new version and 0.13.2 doesn't manifest this problem. Thanks!