Bug 212162 - netcat (nc) does not close TCP stream / exit after end of input stream
Summary: netcat (nc) does not close TCP stream / exit after end of input stream
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.3-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Xin LI
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-25 22:17 UTC by Jeffrey Baitis
Modified: 2017-02-10 22:01 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Baitis 2016-08-25 22:17:16 UTC
To reproduce, use two terminals. In the first, execute:
$ nc -l 2222

In the second terminal, execute:
$ echo "hi" | nc localhost 2222

This command will hang.


My expectation is that nc will terminate once the end of the input stream is reached.

Contrast with the behaviour of socat, which seems correct. Try this command:
$ echo "hi" | socat - TCP:localhost:2222

Both listener and sender processes exit.
Comment 1 Xin LI freebsd_committer freebsd_triage 2016-08-25 23:07:08 UTC
This is WAI.  Specify -N if you need this behavior.
Comment 2 Jeffrey Baitis 2016-08-25 23:20:41 UTC
Wow, how did I miss this option? Thanks, and sorry.
Comment 3 Dmitri Goutnik freebsd_committer freebsd_triage 2017-02-10 22:01:53 UTC
If -N is now required to have input streams closed on EOF, nc(1) manpage needs to be updated to reflect this fact, specifically an example in CLIENT/SERVER MODEL section.