See You Again

一个异常的socket连接导致服务无法启动

今天重启了一下后端服务,发现启动不起来了,一直报错(急死宝宝了):

  1. Failed to bind NettyServer on /0.0.0.0:20991, cause: Failed to bind to: /0.0.0.0:20991

初步看是端口被占用了,可是也没发现有什么服务用这个端口……终于发现了有一个可疑的连接,没有正常释放端口:

  1. $ netstat -ap |grep 20991
  2. (Not all processes could be identified, non-owned process info
  3. will not be shown, you would have to be root to see it all.)
  4. tcp 1 0 127.0.0.1:20991 127.0.0.1:ndmp CLOSE_WAIT 25864/java

原来这个 CLOSE_WAIT 状态在搞鬼,正常情况下应该发 ACK 和 FIN 包然后进入 LAST_ACK 状态的,可能出现了什么异常,卡在这个状态了,然后这个连接一直没有释放!下面这张图可以温习一下 TCP 的三次握手和四次挥手协议:
TCP

那就有解决办法了,强制杀掉它:

  1. $ kill -9 25864
  2. $ netstat -ap |grep 20991
  3. (Not all processes could be identified, non-owned process info
  4. will not be shown, you would have to be root to see it all.)
  5. tcp 1 1 127.0.0.1:20991 127.0.0.1:ndmp LAST_ACK -
  6. $ netstat -ap |grep 20991
  7. (Not all processes could be identified, non-owned process info
  8. will not be shown, you would have to be root to see it all.)

执行完 kill 命令这个连接就变成 LAST_ACK 状态了,过一会这个连接就正常释放了。OK,服务正常启动了:joy:

2017-01-16 喜欢

Copyright © 2015-2018 转载请注明出处

回到顶部 ↑