Skip to content

WSL2 does not set up file descriptors for sub processes on the host #14201

@OrKoN

Description

@OrKoN

Windows Version

10.0.22631.6199

WSL Version

2.6.3.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

6.6.87.2-1

Distro Version

Ubuntu 24.04

Other Software

Node 24.13.0

Repro Steps

The repro uses Node.js but in the original problem the parent process is node and the child process is Google Chrome.

The parent script starts a subprocess with 5 file descriptors. stdin, stdout, stderr + 2 custom ones. It sends data to the child over the fd 3.

// wslParent.mjs
import { spawn } from "node:child_process";

console.log("spawn")

const child = spawn('node.exe', ["wslChild.mjs"], {
    stdio: ["inherit", "inherit", "pipe", "pipe", "pipe"],
});

console.log("writing to child via fd 3")
child.stdio[3].write('test');

child.on('error', err => {
    console.log('error', err);
});

child.stdio[4].on('data', data => {
    console.log('fd4', data.toString('utf-8'));
})

child.stderr.on('data', data => {
    console.log('stderr', data.toString('utf-8'));
})

setTimeout(() => {
    console.log("parent done");
    process.exit(0)
}, 1000)

The child process reads the data from fd 3.

// wslChild.mjs
import fs from 'node:fs';

const stream = fs.createReadStream(null, { fd: 3 });

stream.on('data', data => {
    console.log('child fd3', data.toString('utf-8'));
})

setTimeout(() => {
    console.log("child done");
    stream.close();
    process.exit(0)
}, 1000)

Run node wslParent.mjs inside the WSL's Ubuntu terminal.

Expected Behavior

This should print the child fd3 test. If you replace node.exe with node to use the node within Ubuntu it works. If node.exe on the host is used, it fails.

Actual Behavior

It errors: "Error: EBADF: bad file descriptor, close" indicating that the file descriptor was not opened.

Diagnostic Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions