From fff50b5472a52ae704bb51ae0c3989f38f582343 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 14 Jan 2014 17:47:27 -0700 Subject: [PATCH] Delete deadlock --- model/model.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/model/model.go b/model/model.go index 572c980bd..188d2c3f3 100644 --- a/model/model.go +++ b/model/model.go @@ -138,7 +138,7 @@ func (m *Model) StartRW(del bool, threads int) { go m.cleanTempFiles() if del { - go m.deleteFiles() + go m.deleteLoop() } } @@ -654,6 +654,8 @@ func (m *Model) recomputeGlobal() { // Must be called with the write lock held. func (m *Model) recomputeNeed() { + var toDelete []File + for n, gf := range m.global { if m.fq.Queued(n) { continue @@ -677,7 +679,7 @@ func (m *Model) recomputeNeed() { } if gf.Flags&protocol.FlagDeleted != 0 { - m.dq <- gf + toDelete = append(toDelete, gf) } else { local, remote := BlockDiff(lf.Blocks, gf.Blocks) fm := fileMonitor{ @@ -691,6 +693,13 @@ func (m *Model) recomputeNeed() { } } } + + go func() { + for _, gf := range toDelete { + // The receive side needs the lock, which we are holding + m.dq <- gf + } + }() } func (m *Model) WhoHas(name string) []string { @@ -713,7 +722,7 @@ func (m *Model) whoHas(name string) []string { return remote } -func (m *Model) deleteFiles() { +func (m *Model) deleteLoop() { for file := range m.dq { if m.trace["file"] { log.Println("FILE: Delete", file.Name)