SSH端口通道断开与“select:无效参数”

我隧道到远程服务器访问私人API。 我正在使用下面的命令(通过在terminal中input)来转发一个端口: ssh -L $local_port:$host:$port -v 。 尝试了许多不同的本地端口(9000,9001等)。

我可以直接从浏览器使用API​​或通过nginx代理几个小时没有问题。 如果从playframework应用程序访问它,ssh会话打印出“select:Invalid argument”并closures连接。

这是日志看起来什么时候发生的事情:

 debug1: channel 1016: free: direct-tcpip: listening port 9001 for ec2-xxx.compute-1.amazonaws.com port 9000, connect from 127.0.0.1 port 65349, nchannels 1 select: Invalid argument Connection to ec2-xxx.compute-1.amazonaws.com closed. Transferred: sent 243904, received 64728 bytes, in 87.8 seconds Bytes per second: sent 2778.0, received 737.2 debug1: Exit status -1 

游戏应用程序使用AsyncHttpClient来发出GET请求localhost:$ local_port。

在连接端有没有解决这个问题? 例如让SSH忽略错误并继续连接?

我只是注意到你的debugging输出说通道1016.我怀疑你用完了文件描述符。 我只是检查了我的笔记本电脑,ulimit -a显示了我最多1024个。所以,我想你也打了。 理想的解决scheme是弄清楚你是如何使用这么多的同步文件描述符,并以某种方式减less。

另一种方法是简单地提高打开的文件描述符的最大数量:

  (useful debug commands here) lsof -p <pid> should show you the open filedescriptors in use by a process, btw. ulimit -a should show you your soft limits in this specific shell ulimit -aH should show you the hard limits in this specific shell cat /proc/<pid>/limits should show you the limits in effect on a specific process. 

要达到fd限制,需要在两台机器上编辑/etc/security/limits.conf,以包含以下几行:

 * hard nofile 4096 * soft nofile 4096 root hard nofile 4096 root soft nofile 4096 

这些刚刚重新configuration的限制只有在您再次login时才会生效。 我经常ssh本地主机来testing这种types的东西,但如果我是你,我会尽可能重启。

如果你不能重新启动你的远程机器,那么至less我会重新启动sshd。 再次使用ssh之前,请使用ulimit -a来确认您的最大打开文件或文件描述符是4096。

当你ssh到远程机器运行ulimit -nvalidation它说4096。

祝你好运。

以前的答案更可能是正确的,但是如果增加文件句柄的数量并没有帮助,则可能需要检查您的login文件(.bashrc,.bash_profile,.login,/ etc / login等),以便正确使用内置的bash函数“select” – 请参阅man bash获取更多信息。