Skip to content

Commit

Permalink
agent: bounce session after failed status update
Browse files Browse the repository at this point in the history
Previously, failed calls on an agent session to UpdateTaskStatus weren't
causing the agent to fall back into the session creation retry loop.
Without the retry loop, the agent ends up pounding the dispatcher with
status updates that will never drain.

This PR closes the session on a fatal error, ensuring that the agent
will fallback into a retry loop.

Signed-off-by: Stephen J Day <[email protected]>
  • Loading branch information
stevvooe committed Sep 15, 2016
1 parent 3f3d300 commit 353423b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ func (a *Agent) UpdateTaskStatus(ctx context.Context, taskID string, status *api
if err == errTaskUnknown {
err = nil // dispatcher no longer cares about this task.
} else {
log.G(ctx).WithError(err).Error("sending task status update failed")
log.G(ctx).WithError(err).Error("closing session after fatal error")
session.close()
}
} else {
log.G(ctx).Debug("task status reported")
Expand Down
13 changes: 7 additions & 6 deletions agent/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"errors"
"sync"
"time"

"github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -41,6 +42,7 @@ type session struct {

registered chan struct{} // closed registration
closed chan struct{}
closeOnce sync.Once
}

func newSession(ctx context.Context, agent *Agent, delay time.Duration, sessionID string, description *api.NodeDescription) *session {
Expand Down Expand Up @@ -338,15 +340,14 @@ func (s *session) sendTaskStatuses(ctx context.Context, updates ...*api.UpdateTa
}

func (s *session) close() error {
select {
case <-s.closed:
return errSessionClosed
default:
s.closeOnce.Do(func() {
if s.conn != nil {
s.agent.config.Managers.ObserveIfExists(api.Peer{Addr: s.addr}, -remotes.DefaultObservationWeight)
s.conn.Close()
}

close(s.closed)
return nil
}
})

return nil
}

0 comments on commit 353423b

Please sign in to comment.