MCPcopy Index your code
hub / github.com/koding/kite / renewLoop

Method renewLoop

tokenrenewer.go:74–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72}
73
74func (t *TokenRenewer) renewLoop() {
75 t.renewLoopWG.Add(1)
76 defer t.renewLoopWG.Done()
77
78 // renews token before it expires (sends the first signal to the goroutine below)
79 go time.AfterFunc(t.renewDuration(), t.sendRenewTokenSignal)
80
81 // renew token on signal util remote kite disconnects.
82 for {
83 select {
84 case <-t.signalRenewToken:
85 switch err := t.renewToken(); {
86 case err == nil:
87 go time.AfterFunc(t.renewDuration(), t.sendRenewTokenSignal)
88 case err == ErrNoKitesAvailable || strings.Contains(err.Error(), "no kites found"):
89 // If kite went down we're not going to renew the token,
90 // as we need to dial either way.
91 //
92 // This case handles a situation, when kite missed
93 // disconnect signal (observed to happen with XHR transport).
94 default:
95 t.localKite.Log.Error("token renewer: %s Cannot renew token for Kite: %s I will retry in %d seconds...",
96 err, t.client.ID, retryInterval/time.Second)
97 // Need to sleep here litle bit because a signal is sent
98 // when an expired token is detected on incoming request.
99 // This sleep prevents the signal from coming too fast.
100 time.Sleep(1 * time.Second)
101 go time.AfterFunc(retryInterval, t.sendRenewTokenSignal)
102 }
103 case <-t.disconnect:
104 return
105 }
106 }
107}
108
109// The duration from now to the time token needs to be renewed.
110// Needs to be calculated after renewing the token.

Callers 1

startRenewLoopMethod · 0.95

Calls 4

renewDurationMethod · 0.95
renewTokenMethod · 0.95
AddMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected