nodejs / nodejs/node

Inconsistent behavior of `stdio[3]: 'ignore'`

Aperta
#52,422 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

child_process stale
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Version

v21.7.2

Platform

Linux my-laptop 6.5.0-26-generic #26-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 5 21:19:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

child_process

What steps will reproduce the bug?

With print.js:

import {writeSync} from 'node:fs'

const fdNumber = Number(process.argv[2])
writeSync(fdNumber, '.')

With example.js:

import {spawn} from 'node:child_process'

spawn('node', ['./print.js', '1'], {stdio: ['pipe', 'ignore', 'inherit', 'ignore']})

Prints nothing. But:

import {spawn} from 'node:child_process'

spawn('node', ['./print.js', '3'], {stdio: ['pipe', 'ignore', 'inherit', 'ignore']})

Prints the following:

node:fs:933
  handleErrorFromBinding(ctx);
  ^

Error: EINVAL: invalid argument, write
    at writeSync (node:fs:933:3)
    at file:///home/ether/Desktop/print.js:4:1
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12) {
  errno: -22,
  syscall: 'write',
  code: 'EINVAL'
}

Node.js v21.7.2
How often does it reproduce? Is there a required condition?

No.

What is the expected behavior? Why is that the expected behavior?

ignore should behave consistently regardless of the same descriptor.

What do you see instead?

ignore's behavior differs between stdio[1] and stdio[3].

Additional information

I understand the reason might be that child processes should always have a stdin/stdout/stderr even when ignored, while this does not apply to other file descriptors. So stdio[3]: 'ignore' probably results in no file descriptor being created, as opposed to stdio[1]: 'ignore'.

On one hand, the current behavior is more efficient, as it does not waste creating a file descriptor that's not going to be used.
On the other hand, this results in inconsistent behavior.

Any change there would be breaking too. So this probably won't be fixed, but I reported it in case this was not intentional.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui la riproduzione da print.js e example.js per confermare la differenza tra stdio[1] e stdio[3]. Esamina quindi l’implementazione di child_process e i test correlati per determinare se il comportamento del descrittore è intenzionale. Il lavoro è completato quando il comportamento è reso coerente con la copertura dei test oppure è stata stabilita la sua motivazione documentata e sensibile alla compatibilità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
backend, operating-systems
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.