Fix deadlock when deleting actors

This commit is contained in:
Sasha Koshka 2025-09-14 19:22:42 -04:00
parent 3d25441e7a
commit 02f06d857e

View File

@ -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: