aggV3.rotate() unlock in defer to prevent deadlock

This commit is contained in:
alex.sharov 2023-05-05 11:08:37 +07:00
parent f90337dbe5
commit 9a4582989a

View File

@ -780,9 +780,10 @@ type flusher interface {
Flush(ctx context.Context, tx kv.RwTx) error Flush(ctx context.Context, tx kv.RwTx) error
} }
func (a *AggregatorV3) Flush(ctx context.Context, tx kv.RwTx) error { func (a *AggregatorV3) rotate() []flusher {
a.walLock.Lock() a.walLock.Lock()
flushers := []flusher{ defer a.walLock.Unlock()
return []flusher{
a.accounts.Rotate(), a.accounts.Rotate(),
a.storage.Rotate(), a.storage.Rotate(),
a.code.Rotate(), a.code.Rotate(),
@ -791,7 +792,9 @@ func (a *AggregatorV3) Flush(ctx context.Context, tx kv.RwTx) error {
a.tracesFrom.Rotate(), a.tracesFrom.Rotate(),
a.tracesTo.Rotate(), a.tracesTo.Rotate(),
} }
a.walLock.Unlock() }
func (a *AggregatorV3) Flush(ctx context.Context, tx kv.RwTx) error {
flushers := a.rotate()
defer func(t time.Time) { log.Debug("[snapshots] history flush", "took", time.Since(t)) }(time.Now()) defer func(t time.Time) { log.Debug("[snapshots] history flush", "took", time.Since(t)) }(time.Now())
for _, f := range flushers { for _, f := range flushers {
if err := f.Flush(ctx, tx); err != nil { if err := f.Flush(ctx, tx); err != nil {