fix race condition where leveldb is closed before the iterator

should solve assertion errors like:
db/version_set.cc:710: leveldb::VersionSet::~VersionSet(): Assertion `dummy_versions_.next_ == &dummy_versions_' failed
master
Oliver Tonnhofer 2013-11-08 10:18:14 +01:00
parent 178aba56dd
commit 129799328d
3 changed files with 12 additions and 3 deletions

5
cache/nodes.go vendored
View File

@ -86,6 +86,10 @@ func (p *NodesCache) Iter() chan *element.Node {
ro := levigo.NewReadOptions()
ro.SetFillCache(false)
it := p.db.NewIterator(ro)
// we need to Close the iter before closing the
// chan (and thus signaling that we are done)
// to avoid race where db is closed before the iterator
close(nodes)
defer it.Close()
it.SeekToFirst()
for ; it.Valid(); it.Next() {
@ -97,7 +101,6 @@ func (p *NodesCache) Iter() chan *element.Node {
nodes <- node
}
close(nodes)
}()
return nodes
}

5
cache/relations.go vendored
View File

@ -53,6 +53,10 @@ func (p *RelationsCache) Iter() chan *element.Relation {
ro := levigo.NewReadOptions()
ro.SetFillCache(false)
it := p.db.NewIterator(ro)
// we need to Close the iter before closing the
// chan (and thus signaling that we are done)
// to avoid race where db is closed before the iterator
defer close(rels)
defer it.Close()
it.SeekToFirst()
for ; it.Valid(); it.Next() {
@ -64,7 +68,6 @@ func (p *RelationsCache) Iter() chan *element.Relation {
rels <- rel
}
close(rels)
}()
return rels
}

5
cache/ways.go vendored
View File

@ -72,6 +72,10 @@ func (p *WaysCache) Iter() chan *element.Way {
ro := levigo.NewReadOptions()
ro.SetFillCache(false)
it := p.db.NewIterator(ro)
// we need to Close the iter before closing the
// chan (and thus signaling that we are done)
// to avoid race where db is closed before the iterator
defer close(ways)
defer it.Close()
it.SeekToFirst()
for ; it.Valid(); it.Next() {
@ -82,7 +86,6 @@ func (p *WaysCache) Iter() chan *element.Way {
way.Id = idFromKeyBuf(it.Key())
ways <- way
}
close(ways)
}()
return ways
}