Fix Close race in sqlite storage when batch writes disabled

This commit is contained in:
Matt Joiner 2021-02-03 19:27:26 +11:00
parent 6bc2a2a6ac
commit 371d54ab76
1 changed files with 6 additions and 5 deletions

View File

@ -496,13 +496,13 @@ func getLabels(skip int) pprof.LabelSet {
}
func (p *provider) withConn(with withConn, write bool, skip int) error {
p.closeMu.RLock()
if p.closed {
p.closeMu.RUnlock()
return errors.New("closed")
}
if write && p.opts.BatchWrites {
done := make(chan error)
p.closeMu.RLock()
if p.closed {
p.closeMu.RUnlock()
return errors.New("closed")
}
p.writes <- writeRequest{
query: with,
done: done,
@ -511,6 +511,7 @@ func (p *provider) withConn(with withConn, write bool, skip int) error {
p.closeMu.RUnlock()
return <-done
} else {
defer p.closeMu.RUnlock()
runner, err := p.getReadWithConnRunner()
if err != nil {
return err