forked from sercand/kuberesolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
41 lines (37 loc) · 738 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package kuberesolver
import (
"runtime/debug"
"time"
"google.golang.org/grpc/grpclog"
)
func until(f func(), initialPeriod, maxPeriod time.Duration, stopCh <-chan struct{}) {
select {
case <-stopCh:
return
default:
}
period := initialPeriod
for {
func() {
defer handleCrash()
f()
}()
select {
case <-stopCh:
return
case <-time.After(period):
if period*2 <= maxPeriod {
period *= 2
} else {
period = initialPeriod
}
}
}
}
// HandleCrash simply catches a crash and logs an error. Meant to be called via defer.
func handleCrash() {
if r := recover(); r != nil {
callers := string(debug.Stack())
grpclog.Errorf("kuberesolver: recovered from panic: %#v (%v)\n%v", r, r, callers)
}
}