Skip to content
Snippets Groups Projects
Commit 46abd9ab authored by ale's avatar ale
Browse files

Improve logging messages on group termination

We can report group termination status more accurately if we know that
the termination was requested by the engine. ExecContext() uses
SIGKILL to stop processes, which tends to result in a "killed" error
depending on who wins the errgroup race: this is expected, so it would
be best to report it as such.

Conversely, a successful exit status is unexpected if the engine did
not explicitly request termination.
parent be0fcbde
No related branches found
No related tags found
1 merge request!20Refactor the Engine with stronger guarantees
...@@ -143,6 +143,7 @@ type groupContext struct { ...@@ -143,6 +143,7 @@ type groupContext struct {
cancel context.CancelFunc cancel context.CancelFunc
leases []lease leases []lease
group *Group group *Group
canceled atomic.Bool
} }
func newGroupContext(ttl time.Duration) *groupContext { func newGroupContext(ttl time.Duration) *groupContext {
...@@ -216,8 +217,6 @@ func (e *Engine) buildGroupFromRequest(gctx *groupContext, tx Transaction, req * ...@@ -216,8 +217,6 @@ func (e *Engine) buildGroupFromRequest(gctx *groupContext, tx Transaction, req *
return err return err
} }
//log.Printf("request: %+v", req)
// Create the group. // Create the group.
group, err := newGroup(req, e.registry) group, err := newGroup(req, e.registry)
if err != nil { if err != nil {
...@@ -307,12 +306,12 @@ func (e *Engine) startGroup(gctx *groupContext, tx Transaction) { ...@@ -307,12 +306,12 @@ func (e *Engine) startGroup(gctx *groupContext, tx Transaction) {
go func() { go func() {
err := tx.Execute(gctx.ctx) err := tx.Execute(gctx.ctx)
switch { switch {
case errors.Is(err, context.Canceled): case gctx.canceled.Load():
log.Printf("group %s stopped successfully", gid) log.Printf("group %s stopped successfully", gid)
case err != nil: case err != nil:
log.Printf("group %s terminated with error: %v", gid, err) log.Printf("group %s terminated with error: %v", gid, err)
default: default:
log.Printf("group %s terminated successfully", gid) log.Printf("group %s terminated unexpectedly without error", gid)
} }
e.mx.Lock() e.mx.Lock()
...@@ -343,8 +342,10 @@ func (e *Engine) StopGroup(req *StopGroupRequest) error { ...@@ -343,8 +342,10 @@ func (e *Engine) StopGroup(req *StopGroupRequest) error {
if !ok { if !ok {
return fmt.Errorf("group %s not found", id) return fmt.Errorf("group %s not found", id)
} }
log.Printf("terminating group %s", id) log.Printf("terminating group %s", id)
rg.cancel() rg.cancel()
rg.canceled.Store(true)
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment