【发布时间】:2016-06-26 02:07:32
【问题描述】:
我有一个我编写的 golang 程序(它是一个 FTP 服务器),它在运行时具有 100% 的 CPU。我在 strace 中看到:
futex(0xa83918, FUTEX_WAIT, 0, NULL
read(9, "", 4096) = 0
read(9, "", 4096) = 0
read(9, "", 4096) = 0
read(9, "", 4096) = 0
read(9, "", 4096) = 0
read(8, "", 4096) = 0
read(8, "", 4096) = 0
read(8, "", 4096) = 0
read(8, "", 4096) = 0
read(8, "", 4096) = 0
一遍又一遍。它陷入了某种无限循环。它的主要 for 循环是:
for {
tcpConn, err := listener.Accept()
if err != nil {
Server.logger.Print("listening error")
break
}
driver, err := Server.driverFactory.NewDriver()
if err != nil {
Server.logger.Print("Error creating driver, aborting client connection")
} else {
ftpConn := Server.newConn(tcpConn, driver, Server.Auth)
go ftpConn.Serve()
}
}
知道是什么导致了无限循环吗?当程序启动时,它不是处于这种不良状态。它以正常的 cpu 使用率正常循环。它需要运行几个小时才能进入这种糟糕的状态。
【问题讨论】:
-
什么是 fd 9?检查
ls -lah /proc/YOURPID/fd/9 -
TCP ftp-001.foo.bar.com:ftp->1a.a1.11a1.ip4.static.sl-reverse.com:30006 (CLOSE_WAIT)
-
啊,这似乎是我的问题:stackoverflow.com/questions/15912370/…“您的程序仍在运行,并且尚未关闭套接字(内核正在等待它这样做)”
-
这段代码没有显示问题。看起来你的 ftp 包没有正确关闭连接
标签: go infinite-loop ftp-server