Skip to content

[Linux] Extension host crashes because POSIX test-result FIFO file descriptor is closed twice #26173

Description

@Weidav

Type: Bug

Behaviour

When Python testing is active on Linux, the VS Code extension host can crash during cleanup of a python-test-results-* FIFO.

Expected: the FIFO descriptor is closed exactly once and the extension host continues running.

Actual: the FIFO is first closed by its net.Socket. The socket's close handler then schedules another asynchronous fs.close(fd). If Linux reuses that descriptor number before the asynchronous close executes, the second close closes an unrelated descriptor. libuv subsequently receives EBADF from epoll_ctl and aborts the extension host.

The failure is timing-dependent.

Steps to reproduce:

  1. Open a Linux remote workspace with Python extension 2026.4.0.
  2. Enable pytest and project-based testing.
  3. Run tests through the VS Code Testing view.
  4. Continue working while the test-result pipe is being disposed. Concurrent descriptor activity, such as Git operations, makes the race more likely.
  5. Eventually the extension host disconnects and restarts.

I do not yet have a deterministic UI reproduction, but strace -f -k captured the complete descriptor lifecycle described below.

Diagnostic data

Output for Python in the Output panel (View→Output, change the drop-down in the upper-right of the Output panel to Python)

[info] [test-by-project] Activating project-based testing mode
[info] [test-by-project] Discovering projects for workspace
[info] [test-by-project] Registered 4 project(s)
[info] [test-by-project] Activated 4 project(s)

No Python error was logged when the crash occurred because the extension host aborted in native libuv code.

Environment

  • Python extension: ms-python.python 2026.4.0
  • VS Code server: 1.127.0 (4fe60c8b1cdac1c4c174f2fb180d0d758272d713)
  • Node.js: 24.15.0
  • libuv: 1.51.0
  • OS: Ubuntu 24.04.5, x86-64
  • Kernel: 7.0.0-1012-aws
  • Environment: remote Dev Container

Native trace

The relevant strace -f -k -yy sequence is:

# The Python test-result FIFO owns fd 31.
openat(..., "/tmp/python-test-results-<redacted>",
       O_RDONLY|O_NONBLOCK|O_CLOEXEC) = 31

# net.Socket/libuv closes the FIFO.
epoll_ctl(14, EPOLL_CTL_DEL, 31, ...) = 0
close(31</tmp/python-test-results-<redacted>>) = 0
  uv__stream_close
  uv_close
  node::HandleWrap::Close

# Linux reuses fd 31 for an unrelated child-process stdout socket.
socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0,
           [31<UNIX-STREAM>, 82<UNIX-STREAM>]) = 0
  uv_socketpair
  uv_spawn
  node::ProcessWrap::Spawn

# A libuv filesystem worker performs the second asynchronous close.
close(31<UNIX-STREAM>) = 0
  uv__close_nocancel
  uv__fs_work
  worker

# The event loop tries to register the newly created socket.
epoll_ctl(14, EPOLL_CTL_ADD, 31, {events=EPOLLIN, ...})
    = -1 EBADF (Bad file descriptor)
  uv__io_poll
  uv_run
  node::SpinEventLoopInternal

The first and second closes were ~ 177 ms apart. The new socket was created between them.

Suspected source

The current POSIX reader appears to assign ownership of the same descriptor to both net.Socket and the explicit close handler:

https://github.com/microsoft/vscode-python/blob/main/src/client/common/pipes/namedPipes.ts#L191-L197

const fd = await fs.open(pipeName, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
const socket = new net.Socket({ fd });
const reader = new rpc.SocketMessageReader(socket, "utf-8");

socket.on("close", () => {
    fs.close(fd).catch(noop);
    reader.dispose();
});

The trace shows that net.Socket has already closed the descriptor through uv__stream_close before the handler's fs.close(fd) runs.

Draft PR #26082 replaces this implementation with a directly owned FIFO reader and guarded disposal, so it may also fix this crash.

However, those currently describe the five-second FIFO drain delay rather than this extension-host crash.

Extension version: 2026.4.0
VS Code version: Code 1.139.1 (04c0d99f4fb0d8afe6ce4f0c58e31e183ac3e4b1, 2026-09-25T03:40:57Z)
OS version: Darwin arm64 27.0.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.14.2
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Pyenv
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
code-spell-checker str 4.9.3
copilot-chat Git 0.67.0
debugpy ms- 2026.6.0
even-better-toml tam 0.21.2
gitlens eam 19.2.0
indent-rainbow ode 8.3.1
js-debug ms- 1.117.0
js-debug-companion ms- 1.1.3
jsts-chat-features Typ 0.0.4
markdown-all-in-one yzh 3.6.3
markdown-preview-enhanced shd 0.8.39
python ms- 2026.4.0
rainbow-csv mec 3.24.1
remote-ssh ms- 0.128.0
shell-format fox 7.2.8
vscode-database-client2 cwe 9.0.2
vscode-docker ms- 2.0.0
vscode-js-profile-table ms- 1.0.11
vscode-markdownlint Dav 0.62.1
vscode-pylance ms- 2026.4.1
vscode-theme-onedark aka 2.3.0
vscode-yaml red 1.24.0
A/B Experiments
permission_prompt_control:1332567
ccr_pr_nudge_control:1319470
vsc_wsm_c:1340633
ce50c479:1417073
1g5a5742:1379227
3aced641:1389836
jc553158:1416789

Activity

  1. added
    triage-needed
    on Sep 29, 2026
  2. removed
    triage-needed
    on Sep 29, 2026
  3. added 2 commits that reference this issue on Sep 29, 2026
    e226c00
    6e247d3
  4. zuckerruebe commented on Oct 19, 2026

    @zuckerruebe

    I'm hitting this too, but during test discovery, and frequently: the extension host aborts 20–70 s after
    nearly every window reload (10+ times in a few minutes).

    Environment:

    • Python extension 2026.10.0, Python Environments 1.40.0 (project-based testing active), VS Code 1.142.0
    • WSL2 remote (Ubuntu), kernel 6.6.87.2 and 6.18.54.1 (both affected)
    • Multi-root workspace with three pytest-enabled folders, so many discoveries run concurrently at startup

    Core dumps show libuv aborting in the extension host's main loop:

    • With io_uring (default): abort() in uv__epoll_ctl_flush (libuv 1.52.1, src/unix/linux.c:1304)
    • With io_uring disabled (kernel.io_uring_disabled=2): assert(errno == EEXIST) in uv__io_poll
      (linux.c:1427) with errno == EPERM. The watcher belongs to a UV_NAMED_PIPE whose fd number now refers to a
      non-pollable file, consistent with the fd having been closed and reused.

    In 2026.10.0 the POSIX reader still does

    const fd = await fs.open(pipe, O_RDONLY | O_NONBLOCK);
    const socket = new net.Socket({ fd });
    socket.on('close', () => { fs.close(fd).catch(noop); ... });
    

    net.Socket owns and closes the fd, so the fs.close(fd) is a second close that can hit a reused descriptor (e.g.
    another discovery's FIFO). Crashes coincide with bursts of python-test-discovery-* FIFOs being created.
    Dropping the fs.close(fd) (letting the socket own the fd) should fix it.

  5. Weidav commented on Oct 19, 2026

    @Weidav
    Author

    Damian Birchler (@zuckerruebe) try the linked pull request #26174 and built the extension from it. That should fix the issue, if it works for you leave a comment or like there, so that this gets attention from Micrososft

  6. alessionobile commented on Nov 25, 2026

    @alessionobile

    Another data point, from a native Linux desktop (not remote, WSL or a container), during test discovery rather than a test run.

    • VS Code 1.147.0 (Electron 43.8.9), ms-python.python 2026.10.0, Ubuntu, kernel 7.0.0-44
    • Multi-root workspace with 10 folders and python.testing.pytestEnabled: true in user settings, so discovery opens one python-test-discovery-* FIFO per folder at startup
    • The extension host aborts (exit 134) in uv__epoll_ctl_flush called from uv__io_poll, usually 20 to 40 s after a window loads, often three times in a row. systemd-coredump recorded 80 aborts with this signature between June and November, across every VS Code release in that period.

    To confirm the source at the JS level, I started an extension host with --inspect-brk-extensions and wrapped process.binding('fs').close and .open before any extension loaded. The host aborted after 23 s. Before that, 6 closes failed with EBADF. All 6 had the same stack, the socket.on('close') handler in createReaderPipe, and in each the fd had last been opened as /run/user/<uid>/python-test-discovery-<id>. In 3 of them, unrelated code (VS Code's own readFile) had reused and closed the same number in between.

    main (280bd57) still has the second fs.close(fd). #26174 removes exactly that call and is approved. Merging it should fix the discovery-pipe crash as well as the result-pipe one. Our only workaround is to turn pytest discovery off for most folders.

    Stack of the failing close (minified 2026.10.0 build)
    at Object.close (node:fs:570:11)
    at <global fs patches from two other extensions (graceful-fs), pass-through>
    at out/client/extension.js:2:1297059              fs-extra universalify (promisified close)
    at new Promise (<anonymous>)
    at out/client/extension.js:2:1297037
    at Socket.<anonymous> (out/client/extension.js:2:231972)   createReaderPipe: socket.on('close', () => fs.close(fd))
    at Socket.emit (node:events:526:24)
    at Pipe.<anonymous> (node:net:362:12)
    
  7. sagar-aps-MaMaTa commented on Nov 27, 2026

    @sagar-aps-MaMaTa

    One more data point, with a third crash signature that points at the same double close.

    • VS Code server 1.146–1.148 (server Node 24.22.1 at 1.146), WSL2 remote, Ubuntu 24.04.3, kernel 6.6.87.2, ext4
    • ms-python.python 2026.10.0, Python Environments 1.44.0 (project-based testing active)
    • Multi-root workspace with ~20 folders, most with python.testing.pytestEnabled, so each discovery round opens ~20 python-test-discovery-* FIFOs at once
    • 33 extension host aborts between 2026-11-10 and 2026-11-27, often three in a row (each restart triggers discovery again). Bursts also follow creating a git worktree inside the workspace, which makes project-based testing rediscover every folder.

    A watcher took a snapshot of the extension host's open fds every second and kept the core dumps. 12 of the 13 aborts captured with full data show assert(errno == EEXIST) at linux.c:1427. One core caught a different assertion in the same block, assert(op == EPOLL_CTL_ADD) at linux.c:1426:

    #7 uv__io_poll (loop=<default_loop_struct>, timeout=0) at ../deps/uv/src/unix/linux.c:1426
       fd = 40, op = 3 (EPOLL_CTL_MOD), errno = 2 (ENOENT), e.events = EPOLLIN
    

    So libuv tried to modify a watcher for fd 40 that the kernel no longer had registered. The fd had been closed under libuv and reused. The fd snapshots before the abort show fd 40 cycling through python-test-discovery-* FIFOs, then sockets:

    13:57:07  40 -> /mnt/wslg/runtime-dir/python-test-discovery-f1fc...
    13:57:10  40 -> /mnt/wslg/runtime-dir/python-test-discovery-57f0...
    13:57:11  40 -> socket:[133131]
    13:57:12  40 -> socket:[133222]
    13:57:13  abort
    

    Twelve of the 13 aborts the watcher caught had discovery FIFOs open at the moment of the crash. Two had a mkfifo child still running.

    The double close is still in the shipped 2026.10.0 build (createReaderPipe: r.on("close",()=>{l.close(n).catch(y.noop),i.dispose()})). I removed the l.close(n) locally, the same change as #26174, and will report back whether the aborts stop. Merging #26174 would help everyone with a multi-root workspace on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions