Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After 10 echo commands, the process appears to be blocked #434

Open
I-Want-ToBelieve opened this issue Aug 18, 2020 · 7 comments
Open

After 10 echo commands, the process appears to be blocked #434

I-Want-ToBelieve opened this issue Aug 18, 2020 · 7 comments

Comments

@I-Want-ToBelieve
Copy link

I-Want-ToBelieve commented Aug 18, 2020

It's very easy to reproduce the problem

const execa = require('execa')
const p = execa('powershell.exe', [
  '-NoLogo',
  '-NoExit',
  '-NoProfile',
  '-ExecutionPolicy',
  'ByPass',
])
p.stdout.pipe(process.stdout)
let i = 0
setInterval(() => {
  p.stdin.write(`echo ${i++}\n`)
}, 100)

If you replace PowerShell with CMD, it can last up to 15 times😅

const execa = require('execa')
const p = execa('cmd.exe')
p.stdout.pipe(process.stdout)
let i = 0
setInterval(() => {
  p.stdin.write(`echo ${i++}\n`)
}, 100)

Maybe I did something wrong?

@I-Want-ToBelieve I-Want-ToBelieve changed the title Oddly enough, the process seems to be blocking after the 10th execution the process seems to be blocking after the 10th execution Aug 18, 2020
@I-Want-ToBelieve I-Want-ToBelieve changed the title the process seems to be blocking after the 10th execution The process seems to be blocked after 10 command executions Aug 18, 2020
@I-Want-ToBelieve I-Want-ToBelieve changed the title The process seems to be blocked after 10 command executions After 10 echo commands, the process appears to be blocked Aug 18, 2020
@I-Want-ToBelieve
Copy link
Author

I-Want-ToBelieve commented Aug 18, 2020

With the stdio option added, it works as expected, But I still don't know why...

const execa = require('execa')
const p = execa(
  'powershell.exe',
  [
    '-NoLogo',
    '-NoExit',
    '-NoProfile',
    '-ExecutionPolicy',
    'ByPass',
  ],
+  { stdio: ['pipe', 'inherit', 'pipe'] }
)

let i = 0
setInterval(() => {
  p.stdin.write(`echo ${i++}\n`)
}, 100)

@I-Want-ToBelieve
Copy link
Author

I-Want-ToBelieve commented Aug 18, 2020

I ran more tests to try to find out why

Work as expected:

const EOL = require('os').EOL
const spawn = require('child_process').spawn

const p = spawn(
  'powershell.exe',
  ['-NoLogo', '-NoExit', '-NoProfile', '-ExecutionPolicy', 'ByPass'],
  { stdio: ['pipe', 'pipe', 'pipe'] }
)

const arr = []

p.stdout.on('data', data => void arr.push(data.toString()))

let i = 0
const id = setInterval(() => {
  p.stdin.write(`echo ${i++}${EOL}`)
}, 100)

setTimeout(() => {
  clearInterval(id)
  p.kill()
  console.log(arr)
}, 3e3)

Not working as expected:

const EOL = require('os').EOL
const execa = require('execa')

const p = execa(
  'powershell.exe',
  ['-NoLogo', '-NoExit', '-NoProfile', '-ExecutionPolicy', 'ByPass'],
  { stdio: ['pipe', 'pipe', 'pipe'] }
)

const arr = []

p.stdout.on('data', data => void arr.push(data.toString()))

let i = 0
const id = setInterval(() => {
  p.stdin.write(`echo ${i++}${EOL}`)
}, 100)

setTimeout(() => {
  clearInterval(id)
  p.kill()
  console.log(arr)
}, 3e3)

Work as expected:

const EOL = require('os').EOL
const execa = require('execa')
const fs = require('fs')

const out = fs.openSync('./out.log', 'a')

const p = execa(
  'powershell.exe',
  ['-NoLogo', '-NoExit', '-NoProfile', '-ExecutionPolicy', 'ByPass'],
  { stdio: ['pipe', out, 'pipe'] }
)

let i = 0
const id = setInterval(() => {
  p.stdin.write(`echo ${i++}${EOL}`)
}, 100)
setTimeout(() => {
  clearInterval(id)
  p.kill()
}, 3e3)

Work as expected:

const spawn = require('child_process').spawn
const p = spawn(
  'powershell.exe',
  ['-NoLogo', '-NoExit', '-NoProfile', '-ExecutionPolicy', 'ByPass'],
  { stdio: ['pipe', 'pipe', 'pipe'] }
)
p.stdout.pipe(process.stdout)
let i = 0
setInterval(() => {
  p.stdin.write(`echo ${i++}\n`)
}, 100)

Not working as expected:

const execa = require('execa')
const p = execa(
  'powershell.exe',
  ['-NoLogo', '-NoExit', '-NoProfile', '-ExecutionPolicy', 'ByPass'],
  { stdio: ['pipe', 'pipe', 'pipe'] }
)
p.stdout.pipe(process.stdout)
let i = 0
setInterval(() => {
  p.stdin.write(`echo ${i++}\n`)
}, 100)

@ehmicky
Copy link
Collaborator

ehmicky commented Aug 18, 2020

Hi @doublethinkio,

Could you try adding the windowsHide: false option and see if this fixes your problem? Thanks!

@I-Want-ToBelieve
Copy link
Author

I-Want-ToBelieve commented Aug 18, 2020

Hi @ehmicky
I just tried it and it doesn't fix the problem

image

As the picture shows, it seems to stop there forever, in the expectation that it will go on and on

@I-Want-ToBelieve
Copy link
Author

I-Want-ToBelieve commented Aug 18, 2020

If I execute them 20 times in sync, they will work as expected

Work as expected:

const execa = require('execa')
const p = execa(
  'powershell.exe',
  ['-NoLogo', '-NoExit', '-NoProfile', '-ExecutionPolicy', 'ByPass'],
  { stdio: ['pipe', 'pipe', 'pipe'] }
)
p.stdout.pipe(process.stdout)
let i = 0
while (i < 20) {
  p.stdin.write(`echo ${i++}\n`)
}

image

It seems to be an event loop related problem.

@fivethreeo
Copy link

This seems to happen for me aswell on Debian when running yarn with execa.

@fhenri42
Copy link

fhenri42 commented Oct 5, 2021

Hello,
We have the same issue on mac os, did you find a solution ?
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants