From a5052bc16be8214fec7dc735872ec1a2d55a9b1e Mon Sep 17 00:00:00 2001 From: Jarod Liu Date: Sat, 12 Oct 2013 17:13:49 +0800 Subject: [PATCH] fix a goroutine leak issue --- fsp.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/fsp.go b/fsp.go index 43459e6..0c4fc48 100644 --- a/fsp.go +++ b/fsp.go @@ -62,14 +62,11 @@ func (fs *FspServer) handleConnection(conn *net.TCPConn) { if !ok { return } - case <-fs.timeout(time.Second * 2): + case <-time.After(time.Second * 2): log.Println("Timeout reading from", conn.RemoteAddr().String()) return } - - w := bufio.NewWriterSize(conn, len(fs.policyData)) - w.Write(fs.policyData) - w.Flush() + conn.Write(fs.policyData) log.Println("Sent policy file to", conn.RemoteAddr().String()) } @@ -89,12 +86,3 @@ func (fs *FspServer) read(conn *net.TCPConn) (c chan bool) { }() return } - -func (fs *FspServer) timeout(d time.Duration) (c chan bool) { - c = make(chan bool) - go func() { - time.Sleep(d) - c <- true - }() - return -}