Sqlite backend: Unlock the mutex in Allkeys correctly.

This commit is contained in:
Sascha L. Teichmann 2014-08-11 15:47:20 +02:00
parent d54af34288
commit d96d352db8

View File

@ -216,24 +216,27 @@ func (ss *SqliteSession) CommitTransaction() error {
} }
func (ss *SqliteSession) AllKeys(hash []byte) (keys chan []byte, n int, err error) { func (ss *SqliteSession) AllKeys(hash []byte) (keys chan []byte, n int, err error) {
globalLock.Lock() globalLock.RLock()
defer globalLock.Unlock()
countStmt := ss.txStmt(ss.backend.countStmt) countStmt := ss.txStmt(ss.backend.countStmt)
if err = countStmt.QueryRow().Scan(&n); err != nil { if err = countStmt.QueryRow().Scan(&n); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
err = nil err = nil
} }
globalLock.RUnlock()
return return
} }
keysStmt := ss.txStmt(ss.backend.keysStmt) keysStmt := ss.txStmt(ss.backend.keysStmt)
var rows *sql.Rows var rows *sql.Rows
if rows, err = keysStmt.Query(); err != nil { if rows, err = keysStmt.Query(); err != nil {
globalLock.RUnlock()
return return
} }
keys = make(chan []byte) keys = make(chan []byte)
go func() { go func() {
defer globalLock.RUnlock()
defer rows.Close() defer rows.Close()
defer close(keys) defer close(keys)
for rows.Next() { for rows.Next() {