From 02f06d857ec34679fda765bf607eb50d7dbf0956 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 14 Sep 2025 19:22:42 -0400 Subject: [PATCH] Fix deadlock when deleting actors --- environment.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/environment.go b/environment.go index ec412a5..63e95ae 100644 --- a/environment.go +++ b/environment.go @@ -137,11 +137,13 @@ func (this *environment) Del(ctx context.Context, actors ...Actor) error { channels := []<- chan struct { } { } for _, actor := range actors { info := this.info(actor) - if info.done != nil { + if info.stopped != nil { channels = append(channels, info.stopped) } + info.done() } for _, channel := range channels { + if channel == nil { continue } select { case <- channel: case <- ctx.Done(): @@ -250,7 +252,11 @@ func (this *environment) run(actor Actor) { // contains context information info := this.info(actor) ctx := info.ctx - defer close(info.stopped) + defer func() { + if info.stopped != nil { + close(info.stopped) + } + }() switch actor := actor.(type) { case Runnable: