Fix actors added during initialization process being run twice
Also broke out the emergency halt process into a new function, which is also now ALWAYS called 16 minutes after sigint has been pressed, regardless if the shutdown even began in the first place.
This commit is contained in:
26
phases.go
26
phases.go
@@ -199,6 +199,8 @@ func (this *environment) phase50ConfigurationApplication() bool {
|
||||
actors, done := this.actors.RBorrow()
|
||||
defer done()
|
||||
for _, actor := range sortActors(actors, actors.configurable.all()) {
|
||||
if !actors.info(actor.(Actor)).initial { continue }
|
||||
if this.Verb() { log.Println ("... (50) applying configuration to %s", actor.(Actor).Type())}
|
||||
err := actor.Configure(this.conf)
|
||||
if err != nil {
|
||||
log.Printf (
|
||||
@@ -213,13 +215,24 @@ func (this *environment) phase50ConfigurationApplication() bool {
|
||||
|
||||
func (this *environment) phase60Initialization() bool {
|
||||
if this.Verb() { log.Println("... (60) initializing") }
|
||||
// this fucking sucks in sorry
|
||||
var initializable []Initializable
|
||||
func() {
|
||||
actors, done := this.actors.RBorrow()
|
||||
defer done()
|
||||
initializable = actors.initializable.all()
|
||||
}()
|
||||
if err := this.initializeActors(this.ctx, initializable...); err != nil {
|
||||
// filter out non-initial actors
|
||||
initializableInitial := initializable
|
||||
index := 0
|
||||
for _, actor := range initializable {
|
||||
if !this.info(actor.(Actor)).initial { continue }
|
||||
initializableInitial = initializable[:index + 1]
|
||||
initializableInitial[index] = actor
|
||||
index ++
|
||||
}
|
||||
|
||||
if err := this.initializeActors(this.ctx, initializableInitial...); err != nil {
|
||||
log.Println("XXX (60) failed to initialize:", err)
|
||||
return false
|
||||
}
|
||||
@@ -264,9 +277,11 @@ func (this *environment) phase70RunningBody() bool {
|
||||
actors, done := this.actors.RBorrow()
|
||||
defer done()
|
||||
for _, actor := range actors.runnable.all() {
|
||||
if !actors.info(actor.(Actor)).initial { continue }
|
||||
this.start(actor.(Actor))
|
||||
}
|
||||
for _, actor := range actors.runShutdownable.all() {
|
||||
if !actors.info(actor.(Actor)).initial { continue }
|
||||
this.start(actor.(Actor))
|
||||
}
|
||||
|
||||
@@ -330,14 +345,7 @@ func (this *environment) phase80Shutdown() bool {
|
||||
go func() {
|
||||
<- ctx.Done()
|
||||
if errors.Is(context.Cause(ctx), context.DeadlineExceeded) {
|
||||
log.Println("XXX (80) shutdown timeout expired, performing emergency halt")
|
||||
if Verb() || this.flags.crashOnError {
|
||||
dumpBuffer := make([]byte, 8192)
|
||||
runtime.Stack(dumpBuffer, true)
|
||||
log.Printf("XXX (80) stack trace of all goroutines:\n%s", dumpBuffer)
|
||||
}
|
||||
log.Printf("====== [%s] END =======", this.name)
|
||||
os.Exit(1)
|
||||
this.emergencyHalt("shutdown timeout expired")
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user