From 9c0bc3efc334a439ff2c4a913849683dfab53ead Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 9 Apr 2020 07:40:39 -0700 Subject: [PATCH] bug fix: two read deadlines to prevent memory leak addresses #205 --- src/comm/comm.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/comm/comm.go b/src/comm/comm.go index eafd6d78..4dc1ed4b 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -72,6 +72,9 @@ func (c *Comm) Write(b []byte) (int, error) { } func (c *Comm) Read() (buf []byte, numBytes int, bs []byte, err error) { + // long read deadline in case waiting for file + c.connection.SetReadDeadline(time.Now().Add(3 * time.Hour)) + // read until we get 4 bytes for the header var header []byte numBytes = 4 @@ -102,6 +105,9 @@ func (c *Comm) Read() (buf []byte, numBytes int, bs []byte, err error) { return } buf = make([]byte, 0) + + // shorten the reading deadline in case getting weird data + c.connection.SetReadDeadline(time.Now().Add(10 * time.Second)) for { // log.Debugf("bytes: %d/%d", len(buf), numBytes) tmp := make([]byte, numBytes-len(buf))