Hello when a script that has ssh and cat is passed onto a pipe command then there is a error seen as resource unavailable. Recreation : # cat tp.sh #!/usr/bin/ksh93 export LANG=C { ssh localhost hostname cat /usr/bin/mksysb } | sleep 10 execution output : # ./tp.sh root@localhost's password: cat: output error Resource temporarily unavailable Possible root cause : 1 ssh calls dup() to copy stdout(fd=1) to fd=5. 2 ssh sets O_NONBLOCK flag to fd=5. 3 ssh calls dup2() to assign /dev/null(fd=7) to fd=1. then, ssh closes fd=7. so fd=1 -> /dev/null and fd=5 -> ssh's stdout 4- ssh calls unset_nonblock() to try to clear O_NONBLOCK from fd=1, but it can't because /dev/null has been assigned to fd=1. ssh doesn't clear O_NONBLOCK from ssh's stdout which is fd=5 and ssh closes its stdout(fd=5) without clearing O_NONBLOCK. 5- The subsequent program "cat", fails to write buffers to its stdout, because cat's stdout is connected to the same pipe as ssh, which still has O_NONBLOCK. When executed in debug mode, we get the following error : debug3: send packet: type 1 debug1: fd 0 clearing O_NONBLOCK debug3: fd 1 is not O_NONBLOCK <<<<<< debug1: fd 2 clearing O_NONBLOCK Transferred: sent 1940, received 2424 bytes, in 0.0 seconds Bytes per second: sent 48522.2, received 60627.8 debug1: Exit status 0 cat: output error Resource temporarily unavailable Note: This error is not seen in 7.5p1. If the step 3 mentioned above is commented, then no issue is seen. Please advice on how this can be fixed ? Thanks
Notes : - This issue occurs on even Linux, and all other platform as well. - This issue is not specific to ksh93 alone, it occurs on sh/bash as well - This issue is not specific to mksysb, failure is seen in cat with any files whose size is over several hundred KB
Created attachment 3510 [details] ssh related patch maintain a global variable and dup the STDOUT to it, before dup2 of stdout to /dev/null
Created attachment 3511 [details] clientloop related patch assign back the stored fd to stdout before restoring blocking io
Hello raising the severity to 1 since it is related to user data integrity checks. In some of the scenarios, the output of cat gets truncated with no errors. Please have a look at the attached patch and let me know if any further clarifications is required. Thanks
Created attachment 3519 [details] restore non-blocking status for stdio file descriptors I don't think your patches cover all the cases, particularly the session-multiplexing and stdio forwarding ones. AFAIk this one does.
*** Bug 3310 has been marked as a duplicate of this bug. ***
Fix committed as 7be4ac81366
closing bugs resolved before openssh-8.9