1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-24 08:02:33 +03:00

bug fix: two read deadlines to prevent memory leak

addresses #205
This commit is contained in:
Zack Scholl 2020-04-09 07:40:39 -07:00
parent 386f4ff958
commit 9c0bc3efc3

View File

@ -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))