You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Capturing stderr causes Nushell to hang indefinitely. It might be triggered by interleaving prints to stdout and stderr.
How to reproduce
Have a C program that uses a random mix of printf("...\n") and fprintf(stderr, "...\n")
do -i { random-program | complete } # hangs forever, cannot cancel with Ctrl-C
run-external 'random-program' # same
Outside of a git repo: do -i { git branch | complete } # this one works fine
Expected behavior
Collect both stdout and stderr without hanging. The do -i { git branch | complete } works fine so it might be the alternating stdout / stderr prints mess it up.
Even more interesting, I wrote a modified version that accepts a command line argument:
#include <stdio.h>
#include <stdlib.h>
static int line = 0;
static void
stderr_print (void)
{
fprintf(stderr, "Line %d: stderr\n", line++);
}
static void
stdout_print (void)
{
printf("Line %d: stdout\n", line++);
}
int main (int argc, char ** argv)
{
int i, max = atoi(argv[1]);
for (i=0; i<max; ++i) {
stdout_print();
stderr_print();
}
}
On my system, do -i { ./test 56 | complete } works, but do -i { ./test 57 | complete } hangs. Shell becomes unresponsive to ^C or any other signals, and I have to kill it externally.
This actually seems unrelated to the stdout switching, and instead seems to be related to the size of stderr output. Consider the following snippet:
#include <stdio.h>
#include <stdlib.h>
int
main (int argc, char ** argv)
{
int i, max = atoi(argv[1]);
for (i=0; i<max; ++i) {
fprintf(stderr, "Line %d\n", i);
}
}
I wrote a python script that ranges the inputs from 1 to 100 and counts how many time out (I used a 100ms threshold).
Ignoring my spelling mistakes, there's an interesting jump in failure rates from 75 to 89. Unsure what is causing this, but it appears non-deterministic.
Can confirm that this issue happens when there is no stderr output.
do -i and do -c both hang when passed to complete if there is no stderr output (only stdout). It's like nushell is waiting for some stderr before completing instead of waiting on the external to return with a status code.
This is particularly problematic when a given command may or may not fail and produce stderr or not making it hard to predict whether this will hang the shell. No known work-arounds as far as I can tell short of dropping into another shell inside the do block and putting at least something into the stderr stream before returning.
Activity
fennewald commentedon Apr 14, 2022
Got a MWE:
Interestingly, doesn't fail for small
isfennewald commentedon Apr 14, 2022
Even more interesting, I wrote a modified version that accepts a command line argument:
On my system,
do -i { ./test 56 | complete }works, butdo -i { ./test 57 | complete }hangs. Shell becomes unresponsive to^Cor any other signals, and I have to kill it externally.Version info:
fennewald commentedon Apr 14, 2022
This actually seems unrelated to the stdout switching, and instead seems to be related to the size of stderr output. Consider the following snippet:
I wrote a python script that ranges the inputs from 1 to 100 and counts how many time out (I used a 100ms threshold).
Ignoring my spelling mistakes, there's an interesting jump in failure rates from 75 to 89. Unsure what is causing this, but it appears non-deterministic.
lukexor commentedon Aug 17, 2022
Can confirm that this issue happens when there is no stderr output.
do -ianddo -cboth hang when passed tocompleteif there is no stderr output (only stdout). It's like nushell is waiting for some stderr before completing instead of waiting on the external to return with a status code.This is particularly problematic when a given command may or may not fail and produce stderr or not making it hard to predict whether this will hang the shell. No known work-arounds as far as I can tell short of dropping into another shell inside the
doblock and putting at least something into the stderr stream before returning.