Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify RenewPeriodic to retry failed Renew until TTL elapses #912

Merged
merged 1 commit into from
May 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions api/session.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"fmt"
"time"
)

Expand Down Expand Up @@ -131,19 +132,32 @@ func (s *Session) RenewPeriodic(initialTTL string, id string, q *WriteOptions, d
if err != nil {
return err
}

waitDur := ttl / 2
lastRenewTime := time.Now()
var lastErr error
for {
if time.Since(lastRenewTime) > ttl {
return lastErr
}
select {
case <-time.After(ttl / 2):
case <-time.After(waitDur):
entry, _, err := s.Renew(id, q)
if err != nil {
return err
waitDur = time.Second
lastErr = err
continue
}
if entry == nil {
return nil
waitDur = time.Second
lastErr = fmt.Errorf("No SessionEntry returned")
continue
}

// Handle the server updating the TTL
ttl, _ = time.ParseDuration(entry.TTL)
waitDur = ttl / 2
lastRenewTime = time.Now()

case <-doneCh:
// Attempt a session destroy
Expand Down