From f5a031d72ca3a4d9016b354a0667cfa3bc76a878 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Tue, 16 Aug 2022 11:20:02 +0200 Subject: [PATCH] fix deadlock when sourceOnDemand is true and source exits --- internal/core/path.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/core/path.go b/internal/core/path.go index 2e5496d8..7b61a146 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -460,12 +460,14 @@ func (pa *path) run() { case req := <-pa.chSourceStaticSetNotReady: pa.sourceSetNotReady() + // send response before calling onDemandStaticSourceStop() + // in order to avoid a deadlock due to sourceStatic.stop() + close(req.res) + if pa.hasOnDemandStaticSource() && pa.onDemandStaticSourceState != pathOnDemandStateInitial { pa.onDemandStaticSourceStop() } - close(req.res) - if pa.shouldClose() { return fmt.Errorf("not in use") } @@ -975,7 +977,7 @@ func (pa *path) sourceStaticSetReady(sourceStaticCtx context.Context, req pathSo // this avoids: // - invalid requests sent after the source has been terminated - // - freezes caused by <-done inside stop() + // - deadlocks caused by <-done inside stop() case <-sourceStaticCtx.Done(): req.res <- pathSourceStaticSetReadyRes{err: fmt.Errorf("terminated")} } @@ -991,7 +993,7 @@ func (pa *path) sourceStaticSetNotReady(sourceStaticCtx context.Context, req pat // this avoids: // - invalid requests sent after the source has been terminated - // - freezes caused by <-done inside stop() + // - deadlocks caused by <-done inside stop() case <-sourceStaticCtx.Done(): close(req.res) }