UDP fd leak
leslie-qiwa opened this issue · comments
Leslie Wang commented
Thanks for the package!
In our production, we found FD leak happened from time to time.
Result of netstat
.
udp6 0 0 :::35808 :::* 1/imgsvc
udp6 0 0 :::60384 :::* 1/imgsvc
udp6 0 0 :::35811 :::* 1/imgsvc
udp6 0 0 :::48099 :::* 1/imgsvc
udp6 0 0 :::48101 :::* 1/imgsvc
udp6 0 0 :::44006 :::* 1/imgsvc
udp6 0 0 :::60391 :::* 1/imgsvc
udp6 0 0 :::39913 :::* 1/imgsvc
Result of lsof
imgsvc 1 root 97u IPv6 2499572613 0t0 UDP *:39620
imgsvc 1 root 98u IPv6 2499572625 0t0 UDP *:53887
imgsvc 1 root 99u IPv6 2499574158 0t0 UDP *:35839
imgsvc 1 root 100u IPv6 2499571638 0t0 UDP *:40739
imgsvc 1 root 101u IPv6 2499572645 0t0 UDP *:39966
imgsvc 1 root 102u IPv6 2499574181 0t0 UDP *:37082
imgsvc 1 root 103u IPv6 2499572675 0t0 UDP *:60167
imgsvc 1 root 104u IPv6 2499572703 0t0 UDP *:60581
imgsvc 1 root 105u IPv6 2499572717 0t0 UDP *:60832
imgsvc 1 root 106u IPv6 2499575882 0t0 UDP *:51438
imgsvc 1 root 107u IPv6 2499575159 0t0 UDP *:40391
imgsvc 1 root 108u IPv6 2499575980 0t0 UDP *:47018
imgsvc 1 root 109u IPv6 2499574463 0t0 UDP *:48728
imgsvc 1 root 110u IPv6 2499574738 0t0 UDP *:41585
imgsvc 1 root 111u IPv6 2499579012 0t0 UDP *:50600
imgsvc 1 root 112u IPv6 2499577856 0t0 UDP *:52925
imgsvc 1 root 113u IPv6 2499580893 0t0 UDP *:58937
imgsvc 1 root 114u IPv6 2499581898 0t0 UDP *:56533
imgsvc 1 root 115u IPv6 2499600282 0t0 UDP *:51884
imgsvc 1 root 116u IPv6 2499602688 0t0 UDP *:48947
imgsvc 1 root 117u IPv6 2499600345 0t0 UDP *:37447
We only have one readHandler like example in README, so the leak seems coming from the server itself. Looking at the codes https://github.com/pin/tftp/blob/master/server.go#L416, seems like connection is not closed, so can you please help check if it is the root cause or not.
conn, err := net.ListenUDP("udp", listenAddr)
if err != nil {
return err
}
rf.conn = &connConnection{conn: conn}
}
if s.sendAEnable { /* senderAnticipate if enabled in server */
rf.sendA.enabled = true /* pass enable from server to sender */
sendAInit(&rf.sendA, datagramLength, s.sendAWinSz)
}
s.wg.Add(1)
go func() {
if s.readHandler != nil {
err := s.readHandler(filename, rf)
if err != nil {
rf.abort(err)
}
} else {
rf.abort(fmt.Errorf("server does not support read requests"))
}
s.wg.Done()
}()
Dmitri Popov commented
@leslie-qiwa, please reopen if you still observe FD leak. Thank you for the fix!