From d4e7281fdb41a0ae95150862089eabed2169067b Mon Sep 17 00:00:00 2001 From: Hang Xie <7977860+hangxie@users.noreply.github.com> Date: Sat, 16 Sep 2023 17:50:36 -0700 Subject: [PATCH] fix race condition during WriteStop --- writer/writer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/writer/writer.go b/writer/writer.go index 3efaf5e4..12ea242b 100644 --- a/writer/writer.go +++ b/writer/writer.go @@ -290,6 +290,7 @@ func (pw *ParquetWriter) flushObjs() error { defer func() { wg.Done() if r := recover(); r != nil { + lock.Lock() switch x := r.(type) { case string: errs[index] = errors.New(x) @@ -298,6 +299,7 @@ func (pw *ParquetWriter) flushObjs() error { default: errs[index] = errors.New("unknown error") } + lock.Unlock() } }() @@ -338,12 +340,14 @@ func (pw *ParquetWriter) flushObjs() error { wg.Wait() + lock.Lock() for _, err2 := range errs { if err2 != nil { err = err2 break } } + lock.Unlock() for _, pagesMap := range pagesMapList { for name, pages := range pagesMap {