Bug 156835

Summary: nc enters infinite loop when pipe closes.
Product: [Fedora] Fedora Reporter: David Woodhouse <dwmw2>
Component: ncAssignee: Radek Vokál <rvokal>
Status: CLOSED RAWHIDE QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 1.78-2 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-05-11 10:41:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
strace of offending nc. none

Description David Woodhouse 2005-05-04 16:18:56 UTC
nc is being used as a ssh ProxyCommand. When SSH is finished with it it ought to
die gracefully. It doesn't; it ends up eating CPU...

poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN, revents=POLLHUP}], 2, -1) = 1
poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN, revents=POLLHUP}], 2, -1) = 1
poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN, revents=POLLHUP}], 2, -1) = 1
poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN, revents=POLLHUP}], 2, -1) = 1
poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN, revents=POLLHUP}], 2, -1) = 1

Comment 1 Radek Vokál 2005-05-05 10:17:27 UTC
David, may I have some steps how to reproduce this? 

Comment 2 David Woodhouse 2005-05-05 10:34:14 UTC
I'd imagine this should trigger it for you fairly easily...

cat >> ~/.ssh/config <<EOF
Host *
  ProxyCommand nc %h %p
EOF


Comment 3 David Woodhouse 2005-05-10 17:52:25 UTC
Any progress? If you added that to your SSH configuration you ought to be seeing
a lot of this now...

Comment 4 Radek Vokál 2005-05-11 10:09:59 UTC
Nope, I still don't see this. Running nc host 22 gives no errors and if I try
your steps, I see that nc is running while sshed and after closing the ssh
session nc ends corectly .. 

Comment 6 David Woodhouse 2005-05-11 10:19:27 UTC
#0  0x0ff43cb8 in poll () from /lib/libc.so.6
#1  0x10001928 in readwrite (nfd=3) at netcat.c:615
#2  0x10002278 in main (argc=Variable "argc" is not available.
) at netcat.c:375


Comment 7 David Woodhouse 2005-05-11 10:24:33 UTC
Created attachment 114240 [details]
strace of offending nc.

Comment 8 Radek Vokál 2005-05-11 10:37:13 UTC
The else branch looks really strange to me. If you're calling exec on nc, should
this create a whole new shell for nc? That's maybe why it's still open after
closing ssh session. 

Comment 9 David Woodhouse 2005-05-11 10:43:53 UTC
fsh isn't a shell. It's a faster version of ssh, which re-uses a single
authenticated connection for running multiple commands. 

The logic is "if we're within the internal network use netcat, else ssh to the
bastion host and run netcat there". It's the former case which is failing. 

I don't actually know why it's not 'exec nc' in the first case, which does also
work around the problem -- but fixing netcat to react appropriately to POLLHUP
is also appropriate.