Skip to content

Commit

Permalink
feat(daemon): add Err() to retrieve the tomb death reason (#453)
Browse files Browse the repository at this point in the history
Daemon has a `.Dying()` method that mirrors the
[`Tomb.Dying()`](https://pkg.go.dev/gopkg.in/tomb.v2#Tomb.Dying) API,
but not `.Err()` for the
[`Tomb.Err()`](https://pkg.go.dev/gopkg.in/tomb.v2#Tomb.Err) API. Add a
`.Err()` pass-through function and print out the server exit reason for
easier debugging should one of the daemon tomb goroutines die.
  • Loading branch information
thp-canonical authored Jul 18, 2024
1 parent 02e5d2d commit a150d22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internals/cli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ out:
break out
case <-d.Dying():
// something called Stop()
logger.Noticef("Server exiting!")
logger.Noticef("Server exiting! Reason: %v", d.Err())
break out
case <-checkTicker:
if err := sanityCheck(); err == nil {
Expand Down
6 changes: 6 additions & 0 deletions internals/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,12 @@ func (d *Daemon) Dying() <-chan struct{} {
return d.tomb.Dying()
}

// Err returns the death reason, or ErrStillAlive
// if the tomb is not in a dying or dead state.
func (d *Daemon) Err() error {
return d.tomb.Err()
}

func clearReboot(st *state.State) {
// FIXME See notes in the state package. This logic should be
// centralized in the overlord which is the orchestrator. Right
Expand Down

0 comments on commit a150d22

Please sign in to comment.