From 4ef89f651b225e3efbcb5f9c044456cc63d7554d Mon Sep 17 00:00:00 2001 From: Termina1 Date: Fri, 27 Dec 2024 13:17:15 +0200 Subject: [PATCH] do not drain if db is closed --- chotki.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chotki.go b/chotki.go index 24bd118..d09a058 100644 --- a/chotki.go +++ b/chotki.go @@ -159,7 +159,7 @@ type Chotki struct { src uint64 clock rdx.Clock - lock sync.Mutex + lock sync.RWMutex db *pebble.DB net *protocol.Net dir string @@ -661,6 +661,11 @@ func (cho *Chotki) drain(ctx context.Context, recs protocol.Records) (err error) } func (cho *Chotki) Drain(ctx context.Context, recs protocol.Records) (err error) { + cho.lock.RLock() + defer cho.lock.RUnlock() + if cho.db == nil { + return ErrClosed + } EventsBatchSize.Observe(float64(len(recs))) return cho.drain(ctx, recs) }