From ed72c678f8ec2a9409badb7ca6732b126f11e0ee Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 5 Oct 2015 22:56:16 +0100 Subject: [PATCH] Protect accounting from being closed twice --- fs/accounting.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/accounting.go b/fs/accounting.go index 89d293b02..da8901310 100644 --- a/fs/accounting.go +++ b/fs/accounting.go @@ -256,6 +256,7 @@ type Account struct { lpTime time.Time // Time of last average measurement lpBytes int // Number of bytes read since last measurement avg ewma.MovingAverage // Moving average of last few measurements + closed bool // set if the file is closed exit chan struct{} // channel that will be closed when transfer is finished } @@ -408,9 +409,13 @@ func (file *Account) String() string { // Close the object func (file *Account) Close() error { - close(file.exit) file.mu.Lock() defer file.mu.Unlock() + if file.closed { + return nil + } + file.closed = true + close(file.exit) Stats.inProgress.clear(file.name) return file.in.Close() }