0

Environment: CentOS 6.6

When running this simple test (from myclient):

while true; do rsh myserver "echo OK"; done

After ~500 iterations, the server runs out of ports.

netstat -anp on the server shows:

tcp        0      0 myserver:1008              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:975               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:998               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:991               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1007              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1000              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:990               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:979               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1003              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:988               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:984               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1002              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:997               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1019              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:995               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:993               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1004              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1017              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1013              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1011              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1009              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:994               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:987               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:986               myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1012              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1010              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:1014              myclient:922              TIME_WAIT   -
tcp        0      0 myserver:996               myclient:922              TIME_WAIT   -

922 is the RSH stderr port (from monitoring with wireshark).

After approximatively one minute, the sockets are closed on the server and new connections can be made.

So it seems the client or the server fails to properly close these sockets, and they just timeout.

Is this a bug in rsh ?

Any idea to work around this ? I can see BSD's rsh has a --no-stderr option, but Linux does not seem to.

  • 1
    Do you really need to use rsh? Out of the box it's incredibly insecure and in almost all cases it can (and should) be replaced with ssh. – roaima Sep 16 '16 at 18:48
  • I don't need to, I actually went with ssh. This is for data transfers within a safe, isolated cluster of machines, so security is not an issue. I could achieve better transfer speeds using rsh, because encryption cannot be disabled on ssh. rsh is the only "builtin" solution for transfering full speed from a remote machine AFAIK, otherwise you have to deploy your own daemon to serve the data. – nicoulaj Sep 16 '16 at 18:59
  • In that case, unless the question really is about the many sockets hitting TIME_WAIT and locking up the rsh daemon, please could you clarify what it is that you want to achieve with these many rsh invocations. It's difficult to suggest a work-around without knowing what you're trying to do. – roaima Sep 16 '16 at 20:25
1
+50

Hit this before in my life... the TIME_WAIT is an artifact of TCP/IP so you are stuck with it. It can be tweaked via /proc (see serverfault 23385) but a better way would be a solution that opened a persistent socket that works as long as needed.

  generate_lots_of_lines | ssh myhost 'while read line; do echo ":$line"; done;'

This way you can have one connection do many things based on what the client sends the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.