From c0064323d8c33fe972df3869557a71fbdf20be02 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 23 Nov 2025 13:38:54 -0500 Subject: [PATCH] Don't attempt to restart non-resettable actors --- environment.go | 15 ++++++++++++--- run.go | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/environment.go b/environment.go index ba8dc93..909f140 100644 --- a/environment.go +++ b/environment.go @@ -236,8 +236,9 @@ func (this *environment) start(actor Actor) { go this.run(actor) } -// run runs the given actor, restarting it if it fails. This function will exit -// when the actor's context is canceled. The actor will be removed from the +// run runs the given actor. This function will exit +// when the actor's context is canceled, or the actor has stopped or exited. +// The actor will be removed from the // environment once this function exits, and the environment's wait group // counter will be decremented. note that this function will never increment the // wait group counter, so start should usually be used instead. @@ -349,6 +350,13 @@ func (this *environment) runRunnable(ctx context.Context, actor Runnable) (stopE if this.flags.crashOnError { panic(fmt.Sprint(err)) } + + // if an actor isn't resettable, don't reset + // or restart it + if _, ok := actor.(Resettable); !ok { + stopErr = err + return + } } // restart logic @@ -373,7 +381,8 @@ func (this *environment) runRunnable(ctx context.Context, actor Runnable) (stopE restartInterval = restartInitialInterval } - // reset if needed + // reset if needed. this condition will always be true because + // this code path is restricted to Resettable anyway if actor, ok := actor.(Resettable); ok { if this.Verb() { log.Printf("... [%s] resetting", typ) } func() { diff --git a/run.go b/run.go index 5ef26c0..05adf30 100644 --- a/run.go +++ b/run.go @@ -52,8 +52,8 @@ var env environment // // 70. Running: Actors which implement [Runnable] or [RunShutdownable] are // run, each in their own goroutine. The environment is able to restart -// actors which have failed, which entails resetting the actor if it -// implements [Resettable], and running the actor again within the same +// actors which have failed if they implement [Resettable], which entails +// resetting the actor and running it again within the same // goroutine. If an actor does not run for a meaningful amount of time // after resetting/initialization before failing, it is considered erratic // and further attempts to restart it will be spaced by a limited,