From 86aeed93db2f66b0de2b007a9fcbb5ea65c3e6b9 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Fri, 6 Aug 2021 09:48:26 -0700 Subject: [PATCH] move mutex to avoid race condition #407 --- src/croc/croc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/croc/croc.go b/src/croc/croc.go index b208f20..95790ca 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -1454,13 +1454,14 @@ func (c *Client) receiveData(i int) { c.mutex.Lock() _, err = c.CurrentFile.WriteAt(data[8:], positionInt64) - c.mutex.Unlock() if err != nil { panic(err) } c.bar.Add(len(data[8:])) c.TotalSent += int64(len(data[8:])) c.TotalChunksTransfered++ + // log.Debug(len(c.CurrentFileChunks), c.TotalChunksTransfered, c.TotalSent, c.FilesToTransfer[c.FilesToTransferCurrentNum].Size) + if !c.CurrentFileIsClosed && (c.TotalChunksTransfered == len(c.CurrentFileChunks) || c.TotalSent == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size) { c.CurrentFileIsClosed = true log.Debug("finished receiving!") @@ -1483,6 +1484,7 @@ func (c *Client) receiveData(i int) { panic(err) } } + c.mutex.Unlock() } }