From 06e723f6295726de5a4fdc18929e50d1a4898029 Mon Sep 17 00:00:00 2001 From: Viktor Kuzmin Date: Fri, 17 Nov 2023 16:45:39 +0200 Subject: [PATCH] Waiting for writes to complete with acquired locks may lead to deadlock, fixes #4952 --- weed/mount/page_writer/upload_pipeline.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/weed/mount/page_writer/upload_pipeline.go b/weed/mount/page_writer/upload_pipeline.go index 267ea3a4c..bd7fc99dd 100644 --- a/weed/mount/page_writer/upload_pipeline.go +++ b/weed/mount/page_writer/upload_pipeline.go @@ -147,14 +147,17 @@ func (up *UploadPipeline) MaybeReadDataAt(p []byte, off int64, tsNs int64) (maxS } func (up *UploadPipeline) FlushAll() { + up.flushChunks() + up.waitForCurrentWritersToComplete() +} + +func (up *UploadPipeline) flushChunks() { up.chunksLock.Lock() defer up.chunksLock.Unlock() for logicChunkIndex, memChunk := range up.writableChunks { up.moveToSealed(memChunk, logicChunkIndex) } - - up.waitForCurrentWritersToComplete() } func (up *UploadPipeline) maybeMoveToSealed(memChunk PageChunk, logicChunkIndex LogicChunkIndex) {