Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1078244

Summary: ncat client hangs if server terminates first
Product: Red Hat Enterprise Linux 7 Reporter: Jan Stancek <jstancek>
Component: nmapAssignee: Pavel Zhukov <pzhukov>
Status: CLOSED WONTFIX QA Contact: qe-baseos-daemons
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: bpeck, ccgurley, jaster, jburke, ovasik, pbunyan, thomas.oulevey
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-07-25 11:58:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jan Stancek 2014-03-19 13:10:26 UTC
Description of problem:
ncat client doesn't exit if server terminates first.

         server                      client
                          |
ncat -l 8888              |
                          | ncat localhost 8888; echo $?
^C                        |
                          | # ncat keeps running, I have to
                          | # press enter twice to get EPIPE
                          |

Or with unix sockets:
         server                      client
                          |
rm -f /tmp/nc.test        |
ncat -l -U /tmp/nc.test   |         
                          | ncat -U /tmp/nc.test; echo $?
^C                        |
                          | # ncat keeps running, I have to
                          | # press enter to get EPIPE
                          |

With RHEL6.5 nc, client terminates as soon as server side terminates:
         server                      client
                          |
nc -l 8888                |
                          | nc localhost 8888; echo $?
^C                        |
                          | 0
                          |                          


It seems to work fine when client terminates first:
         server                      client
                          |
ncat -l 8888; echo $?     |
                          | ncat localhost 8888
                          | ^C
0                         | 
                          |

         server                           client
                                 |
rm -f /tmp/nc.test               |
ncat -l -U /tmp/nc.test; echo $? |
                                 | ncat -U /tmp/nc.test
                                 | ^C
0                                | 
                                 |


Version-Release number of selected component (if applicable):
nmap-ncat-6.40-4.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
see description

Actual results:
client side remains running

Expected results:
if server is not running anymore, client should exit

Additional info:

Comment 3 Michal Hlavinka 2015-06-29 09:03:39 UTC
This is a side effect of a feature.
ncat uses half-closed socket, so client/server can only read/write from the socket, not both.

S: ncat -l 8888 
C: ncat localhost 8888

instead of terminating the server, try this instead:
S: HELLO
S: <Ctrl-D>
C: BYE

What happened is that server closed socket for writing by calling shutdown(sd, SHUT_WR). Client sees this and continues, because it can still send data (if you do not use --recv-only option). 

Unfortunately, when socket is closed, ncat can't distinguish it whether it's closed or half closed, until it tries to send something. 

IN SHORT: This is not a bug, but expected behaviour. There is even a check for this in upstream regression test suite:

"""PASS Client closes stdout and keeps running after socket EOF"""

I'm trying to discuss this with upstream if they would change the behaviour, but the response rate is really slow. I think, the chance for change is small, but to prevent close/re-open noise, I will move this bug to next release and hope I will have definitive answer by then.

Anyway, consider this bug as closed notabug/wontfix for the time being.

Comment 4 Pavel Zhukov 2017-07-25 16:28:31 UTC
Upstream discussion: 
http://seclists.org/nmap-dev/2017/q2/67

Comment 5 Pavel Zhukov 2017-10-23 15:25:18 UTC
*** Bug 1328996 has been marked as a duplicate of this bug. ***

Comment 6 Pavel Zhukov 2018-02-26 13:43:39 UTC
*** Bug 1548487 has been marked as a duplicate of this bug. ***

Comment 9 Pavel Zhukov 2019-07-25 11:58:18 UTC
Hello,

Looks like it's time to close this bug finally as per https://bugzilla.redhat.com/show_bug.cgi?id=1078244#c3 and upstream discussion.