Description
Test script
Save the following as hang.sh:
#!/bin/sh
# usage: repeat N STR # print STR N times
repeat() {
until [ $1 -le 0 ]; do printf %s "$2"; set -- $(($1-1)) "$2"; done
}
# 16 chars, including the (LF-only) newline
line=$'123456789012345\n'
# repeat $1 times, or 257 if no $1
n=${1-257}
# this works for any number of repeatitions
repeat $n "$line"
echo "[done plain]"
# this hangs if $1 is 257 or more, i.e. the pipe has more than 4096 bytes
repeat $n "$line" | while IFS= read -r x; do printf %s\\n "$x"; done
echo "[done piped]"
Then run brush hang.sh.
Expected behavior:
Prints some lines, the last being [done piped], and brush exits.
Actual behavior
Prints some lines, the last being [done plain], and brush doesn't exit.
Tested using brush 0.4.0 and master, on Windows 10.
Analysis
This was originally encountered when trying shlolcat in brush. It does work on Linux (in brush), but hangs on Windows.
Narrowing it down, it turned out that if a pipe is is passing more than 4096 bytes (as is the default with the test script above), then it hangs.
The test script above takes an optional argument which is the number of times to repeat the line. If it's used with 256 or less, e.g. brush hang.sh 256, then it completes successfully (and doesn't hang). With value of 256, the pipe passes exectly 4096 bytes.
But with an argument of 257 (the default) or more, on Windows, it hangs.
On linux, the same script with brush (musl) doesn't hang even with much bigger values (tried 1000).
As a side note, running shlolcat using brush on windows with very small input files does work correctly (if some internal pipe ends up passing 4096 chars or less).
Description
Test script
Save the following as
hang.sh:Then run
brush hang.sh.Expected behavior:
Prints some lines, the last being
[done piped], and brush exits.Actual behavior
Prints some lines, the last being
[done plain], and brush doesn't exit.Tested using brush 0.4.0 and master, on Windows 10.
Analysis
This was originally encountered when trying shlolcat in brush. It does work on Linux (in brush), but hangs on Windows.
Narrowing it down, it turned out that if a pipe is is passing more than 4096 bytes (as is the default with the test script above), then it hangs.
The test script above takes an optional argument which is the number of times to repeat the line. If it's used with 256 or less, e.g.
brush hang.sh 256, then it completes successfully (and doesn't hang). With value of 256, the pipe passes exectly 4096 bytes.But with an argument of 257 (the default) or more, on Windows, it hangs.
On linux, the same script with brush (musl) doesn't hang even with much bigger values (tried 1000).
As a side note, running shlolcat using brush on windows with very small input files does work correctly (if some internal pipe ends up passing 4096 chars or less).