Skip Menu |
Report information
Id: 127566
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: simon [at] ruderich.org
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Date: Thu, 18 Feb 2016 21:02:26 +0100
To: rakudobug [...] perl.org
From: Simon Ruderich <simon [...] ruderich.org>
Subject: [BUG] run hangs on slurp-rest with :out and :err if command runs background process
Hello, I'm having a weird problem with run. In the following sample, Perl6 waits after "slurping err" when the ssh mux process gets spawned in the background on the initial connection. It waits until the ssh mux process terminates on its own and then prints the output (stdout/stderr) correctly. If the ssh mux process is already running, everthing works fine. my @cmd = « ssh -o Protocol=2 -o ControlMaster=auto -o ControlPath=master-%l-%h-%r -o ControlPersist=30 »; @cmd.append('root@steep', 'ls'); my $p = run @cmd, :!in, :out, :err; say "slurping out"; my $out = $p.out.slurp-rest; say "slurping err"; my $err = $p.err.slurp-rest; $p.out.close; $p.err.close; say "STDOUT: {$out}"; say "STDERR: {$err}"; Removing either or both close doesn't help, however if I don't use :err (and thus don't read from $err), everything works fine as well. Regards Simon -- + privacy is necessary + using gnupg http://gnupg.org + public key id: 0x92FEFDB7E44C32F9
Download signature.asc
application/pgp-signature 819b

Message body not shown because it is not plain text.

Date: Sat, 20 Feb 2016 00:07:04 +0200
From: Peter Pentchev <roam [...] ringlet.net>
To: perl6-compiler [...] perl.org
Subject: Re: [perl #127566] [BUG] run hangs on slurp-rest with :out and :err if command runs background process
Download (untitled) / with headers
text/plain 2.3k
On Thu, Feb 18, 2016 at 12:02:48PM -0800, Simon Ruderich wrote: Show quoted text
> # New Ticket Created by Simon Ruderich > # Please include the string: [perl #127566] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=127566 > > > > Hello, > > I'm having a weird problem with run. In the following sample, > Perl6 waits after "slurping err" when the ssh mux process gets > spawned in the background on the initial connection. It waits > until the ssh mux process terminates on its own and then prints > the output (stdout/stderr) correctly. If the ssh mux process is > already running, everthing works fine. > > my @cmd = « > ssh > -o Protocol=2 > -o ControlMaster=auto > -o ControlPath=master-%l-%h-%r > -o ControlPersist=30 > »; > @cmd.append('root@steep', 'ls');
I don't think this is a Perl problem; I believe it may be a real OpenSSH bug (or, at least, unexpected behavior). The problem is that when your SSH client decides to start the mux process, the latter *does not close* its standard error stream; it keeps file descriptor 2 open to whatever the original SSH client had it open to - usually this is the user's terminal, but in your case, it's the pipe back to your program. Even though the original SSH client process exited, the pipe is still open (to another process, yet still open anyway), and Perl is absolutely correct to wait for everything that has the pipe open to close it. This does not even come from Perl, it's your OS's kernel doing it - but, since there is a process still using the pipe, it's correct to do it that way :( As far as I can see, this behavior - leaving fd 2 open to the original client's standard error stream - is not explicitly documented in either the ssh(1) manual page or the ssh_config(5) one. I've even tried passing the -E option to send the debug logs to someplace else, but it does indeed only affect the debug logs, not the actual standard error stream :( I wonder if it might be worthwhile to raise this with the OpenSSH developers; I could do that if you'd like me to. G'luck, Peter -- Peter Pentchev roam@ringlet.net roam@FreeBSD.org pp@storpool.com PGP key: http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13
Download signature.asc
application/pgp-signature 819b

Message body not shown because it is not plain text.

Subject: Re: [perl #127566] [BUG] run hangs on slurp-rest with :out and :err if command runs background process
Date: Tue, 23 Feb 2016 01:48:07 +0100
To: Peter Pentchev via RT <perl6-bugs-followup [...] perl.org>
From: Simon Ruderich <simon [...] ruderich.org>
Download (untitled) / with headers
text/plain 1.5k
On Fri, Feb 19, 2016 at 02:07:36PM -0800, Peter Pentchev via RT wrote: Show quoted text
> The problem is that when your SSH client decides to start the mux > process, the latter *does not close* its standard error stream; > it keeps file descriptor 2 open to whatever the original SSH client > had it open to - usually this is the user's terminal, but in your > case, it's the pipe back to your program. Even though the original > SSH client process exited, the pipe is still open (to another process, > yet still open anyway), and Perl is absolutely correct to wait for > everything that has the pipe open to close it. This does not even > come from Perl, it's your OS's kernel doing it - but, since there is > a process still using the pipe, it's correct to do it that way :( > > As far as I can see, this behavior - leaving fd 2 open to the original > client's standard error stream - is not explicitly documented in > either the ssh(1) manual page or the ssh_config(5) one. I've even > tried passing the -E option to send the debug logs to someplace else, > but it does indeed only affect the debug logs, not the actual standard > error stream :(
Hello Peter, Thank you for this detailed analysis! I saw the open file descriptor in the debug log but didn't think that it could be the reason for the delay. Show quoted text
> I wonder if it might be worthwhile to raise this with the OpenSSH > developers; I could do that if you'd like me to.
If you'd like to that would be great. Thank you for your quick help. Regards Simon -- + privacy is necessary + using gnupg http://gnupg.org + public key id: 0x92FEFDB7E44C32F9
Download signature.asc
application/pgp-signature 819b

Message body not shown because it is not plain text.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org