1

I have a golang program I wrote (it's an FTP server) that has 100% CPU when running. I see in 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

Over and over. It's caught in some infinite loop. It's main for loop is:

 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()
    }   
  }

Any idea what is causing the infinite loop? When the program starts it's NOT in this bad state. It loops normally with normal cpu usage. It takes several hours of it running before it gets into this bad state.

kichik
  • 33,220
  • 7
  • 94
  • 114
Andrew Arrow
  • 4,248
  • 9
  • 53
  • 80
  • What is fd 9? Check with `ls -lah /proc/YOURPID/fd/9` – kichik Mar 11 '16 at 00:24
  • TCP ftp-001.foo.bar.com:ftp->1a.a1.11a1.ip4.static.sl-reverse.com:30006 (CLOSE_WAIT) – Andrew Arrow Mar 11 '16 at 00:34
  • ah, this seems like my problem: http://stackoverflow.com/questions/15912370/how-do-i-remove-a-close-wait-socket-connection " your program is still running, and hasn't closed the socket (and the kernel is waiting for it to do so)" – Andrew Arrow Mar 11 '16 at 00:43
  • This code doesn't show the problem. It looks like your ftp package isn't closing the connection properly – JimB Mar 11 '16 at 02:25

2 Answers2

3

Turns out this wasn't TCP related at all. This was a while loop in the code never ending because of a "\n" input issue. i.e. I had:

for {
  if something {
    break;
  }
}

And it never broke.

Andrew Arrow
  • 4,248
  • 9
  • 53
  • 80
0

Perhaps try closing the tcpConn when you try to create a new driver on error. Also, try checking that Server.newConn(tcpConn, driver, Server.Auth) actually closes the connection when it's complete.

Dale Annin
  • 11
  • 2