Open hxhue opened 2 months ago
I find there is an easier way to reproduce this. Just type the following command in each terminal (open a few terminals before doing this):
file /proc/$$/fd/* | grep -v 'No such file'
Every terminal shows a different count of symbolic link to /dev/ptmx
entry.
The first terminal (1 fd -> /dev/urandom):
/proc/29722/fd/0: symbolic link to /dev/pts/4
/proc/29722/fd/1: symbolic link to /dev/pts/4
/proc/29722/fd/19: symbolic link to /dev/urandom
/proc/29722/fd/2: symbolic link to /dev/pts/4
/proc/29722/fd/20: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/ptyhost.log
/proc/29722/fd/21: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/network.log
/proc/29722/fd/24: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/remoteagent.log
/proc/29722/fd/255: symbolic link to /dev/pts/4
The second terminal (1 fd -> /dev/urandom and 1 fd -> /dev/ptmx):
/proc/29831/fd/0: symbolic link to /dev/pts/5
/proc/29831/fd/1: symbolic link to /dev/pts/5
/proc/29831/fd/19: symbolic link to /dev/urandom
/proc/29831/fd/2: symbolic link to /dev/pts/5
/proc/29831/fd/20: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/ptyhost.log
/proc/29831/fd/21: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/network.log
/proc/29831/fd/22: symbolic link to /dev/ptmx
/proc/29831/fd/24: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/remoteagent.log
/proc/29831/fd/255: symbolic link to /dev/pts/5
The third terminal (1 fd -> /dev/urandom and 2 fds -> /dev/ptmx):
/proc/29893/fd/0: symbolic link to /dev/pts/6
/proc/29893/fd/1: symbolic link to /dev/pts/6
/proc/29893/fd/19: symbolic link to /dev/urandom
/proc/29893/fd/2: symbolic link to /dev/pts/6
/proc/29893/fd/20: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/ptyhost.log
/proc/29893/fd/21: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/network.log
/proc/29893/fd/22: symbolic link to /dev/ptmx
/proc/29893/fd/24: symbolic link to /home/USER/.vscode-server/data/logs/20240902T140816/remoteagent.log
/proc/29893/fd/25: symbolic link to /dev/ptmx
/proc/29893/fd/255: symbolic link to /dev/pts/6
I also did some research after posting the issue and now understand that /dev/ptmx is a pseudo-terminal master device and not needed by shells (which need slave devices). Maybe there is a missing FD_CLOEXEC
flag during the fork
-exec
of the shells?
AFAIK, that symbolic link creation, symbolic link to /dev/ptmx
, is not coming from VS Code. Can you reproduce in an external terminal?
@Tyriar or @roblourens any thoughts here?
The symbolic links come from Linux's /proc virtual filesystem (only Linux has it). /proc/<pid>/
is a folder describing the process whose pid is <pid>
. /proc/<pid>/fd/
folder contains all open fds shown as symbolic links to actual files on the filesystem.
This doesn't mean that VS Code creates any symbolic links, but means the shells (and their subprocesses) keep those files open when they're running.
I only reproduced the issue in my WSL and a remote Linux server. I don't have a Linux desktop environment for now, but I will see if I can reproduce it on a virtual machine.
The integrated terminal on a Linux desktop (inside a virtual machine) has the same problem. Here are some screenshots.
The issue does not exist in external terminals on a Linux desktop.
There's my .vscode/launch.json, it uses external terminals to launch the given Python file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
}
The contents of main.py:
import os
assert 0 == os.system("file /proc/$$/fd/* | grep -v 'No such file'")
_ = input('Waiting for anything...')
print('<Exited>')
The result is:
Does this issue occur when all extensions are disabled?: Yes
Every new integrated terminal opens /dev/ptmx instead of reusing the old one or opening the new one after closing the old one. This bug occurs both in my WSL and remote Ubuntu server.
Steps to Reproduce when VS Code is connected to WSL (Debian):
a.out
). It's a test program trying to allocate as many fds as possible. It also reports suspicious occupied fds.a.out
in the 1st terminal. The result may be:file
command and its arguments) to the 2nd terminal. The results may be:Conclusion: The first terminal has fds pointing to /dev/urandom and some log files. Every new terminal beginning with the second one opens one more fd pointing to /dev/ptmx and the subprocesses inherit the fds from the terminal.
Other observations: The occupied fds are fixed once the terminal is open. After closing some terminals, the occupied fds in the previously opened terminals are not released, but the fds are released for new terminals.
The results are reproducible on a remote Ubuntu server, except that there is no fd pointing to /dev/urandom, and every new terminal opens /dev/pts/ptmx instead of /dev/ptmx.
I've seen a similar issue: https://github.com/microsoft/vscode/issues/182212, but it doesn't mention WSL or remote servers.