Skip to content

Commit 5d8f0ae

Browse files
committed
grpclb: teach the manual resolver to handle restarts
1 parent 9deee9b commit 5d8f0ae

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

balancer/grpclb/grpclb_util.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,25 @@ import (
6262
type lbManualResolver struct {
6363
scheme string
6464
ccr resolver.ClientConn
65+
ccb balancer.ClientConn
6566

66-
ccb balancer.ClientConn
67+
// Cache the most recently received state update via UpdateState(), and push
68+
// the same when Build() is invoked. This ensures that this manual resolver
69+
// can handle restarts when channel idleness comes into the picture.
70+
stateMu sync.Mutex
71+
lastState resolver.State
72+
stateUpdateRecv bool
6773
}
6874

6975
func (r *lbManualResolver) Build(_ resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) {
7076
r.ccr = cc
77+
78+
r.stateMu.Lock()
79+
if r.stateUpdateRecv {
80+
r.ccr.UpdateState(r.lastState)
81+
}
82+
r.stateMu.Unlock()
83+
7184
return r, nil
7285
}
7386

@@ -85,6 +98,11 @@ func (*lbManualResolver) Close() {}
8598

8699
// UpdateState calls cc.UpdateState.
87100
func (r *lbManualResolver) UpdateState(s resolver.State) {
101+
r.stateMu.Lock()
102+
r.lastState = s
103+
r.stateUpdateRecv = true
104+
r.stateMu.Unlock()
105+
88106
r.ccr.UpdateState(s)
89107
}
90108

0 commit comments

Comments
 (0)