Skip to content

Missing stdout due to closed stream #40

Closed
@AriPerkkio

Description

@AriPerkkio

I ran into edge case while working on Vitest. Unfortunately I was unable to create minimal reproduction. Reproduction with Vitest: AriPerkkio/vitest@de3dc71

When we add exit listener that calls process.exit inside it, Tinyexec loses stdout from that process. This is similar exit handling as tinylibs/picospinner does.

It seems that subprocess.stdout returned from node:child_process.spawn is closed when subprocess.stderr is read. Here's some logging from Vitest's case:

tinyexec/src/main.ts

Lines 216 to 226 in 24e9861

if (this._streamErr) {
for await (const chunk of this._streamErr) {
stderr += chunk.toString();
}
}
if (this._streamOut) {
for await (const chunk of this._streamOut) {
stdout += chunk.toString();
}
}

+ console.log('before', this._streamOut?.closed);
+ // > before false

if (this._streamErr) {
  for await (const chunk of this._streamErr) {
    stderr += chunk.toString();
  }
}

+ console.log('after', this._streamOut?.closed);
+ // > after true

if (this._streamOut) {
  for await (const chunk of this._streamOut) {
    stdout += chunk.toString();
  }
}

To fix these, we'll need to first read stdout.

Replacing tinyexec with node:child_process.execSync works 100% times.

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