Skip to content

Commit b383d99

Browse files
committed
hold read-lock when iterating query results
1 parent 8fa3173 commit b383d99

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

datastore.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ func NewDatastore(path string, opts *Options) (*Datastore, error) {
5353
return nil, err
5454
}
5555

56-
closeLk := sync.RWMutex{}
5756
ds := Datastore{
58-
accessor: &accessor{ldb: db, syncWrites: true, closeLk: &closeLk},
57+
accessor: &accessor{ldb: db, syncWrites: true, closeLk: new(sync.RWMutex)},
5958
DB: db,
6059
path: path,
6160
}
@@ -110,8 +109,6 @@ func (a *accessor) Has(key ds.Key) (exists bool, err error) {
110109
}
111110

112111
func (a *accessor) GetSize(key ds.Key) (size int, err error) {
113-
a.closeLk.RLock()
114-
defer a.closeLk.RUnlock()
115112
return ds.GetBackedSize(a, key)
116113
}
117114

@@ -151,6 +148,8 @@ func (a *accessor) Query(q dsq.Query) (dsq.Results, error) {
151148
}
152149
r := dsq.ResultsFromIterator(q, dsq.Iterator{
153150
Next: func() (dsq.Result, bool) {
151+
a.closeLk.RLock()
152+
defer a.closeLk.RUnlock()
154153
if !next() {
155154
return dsq.Result{}, false
156155
}

0 commit comments

Comments
 (0)