Skip to content

Commit

Permalink
Fix flannel hang if lease expired
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchun committed Jan 22, 2021
1 parent 14d007b commit 78035d0
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 35 deletions.
9 changes: 5 additions & 4 deletions backend/extension/extension_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ func (n *network) Run(ctx context.Context) {

for {
select {
case evtBatch := <-evts:
case evtBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
n.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions backend/ipsec/ipsec_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ func (n *network) Run(ctx context.Context) {

for {
select {
case evtsBatch := <-evts:
case evtsBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
log.Info("Handling event")
n.handleSubnetEvents(evtsBatch)
case <-ctx.Done():
log.Info("Received DONE")
return
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions backend/route_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ func (n *RouteNetwork) Run(ctx context.Context) {

for {
select {
case evtBatch := <-evts:
case evtBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
n.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions backend/route_network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func (n *RouteNetwork) Run(ctx context.Context) {

for {
select {
case evtBatch := <-evts:
case evtBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
n.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions backend/udp/udp_network_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ func (n *network) Run(ctx context.Context) {

for {
select {
case evtBatch := <-evts:
case evtBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
stopProxy(n.ctl)
return
}
n.processSubnetEvents(evtBatch)

case <-ctx.Done():
stopProxy(n.ctl)
return
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions backend/vxlan/vxlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ func (nw *network) Run(ctx context.Context) {

for {
select {
case evtBatch := <-events:
case evtBatch, ok := <-events:
if !ok {
log.Infof("evts chan closed")
return
}
nw.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions backend/vxlan/vxlan_network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ func (nw *network) Run(ctx context.Context) {

for {
select {
case evtBatch := <-events:
case evtBatch, ok := <-events:
if !ok {
log.Infof("evts chan closed")
return
}
nw.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ func MonitorLease(ctx context.Context, sm subnet.Manager, bn backend.Network, wg
log.Info("Lease renewed, new expiration: ", bn.Lease().Expiration)
dur = bn.Lease().Expiration.Sub(time.Now()) - renewMargin

case e := <-evts:
case e, ok := <-evts:
if !ok {
log.Infof("Stopped monitoring lease")
return errCanceled
}
switch e.Type {
case subnet.EventAdded:
bn.Lease().Expiration = e.Lease.Expiration
Expand All @@ -437,10 +441,6 @@ func MonitorLease(ctx context.Context, sm subnet.Manager, bn backend.Network, wg
log.Error("Lease has been revoked. Shutting down daemon.")
return errInterrupted
}

case <-ctx.Done():
log.Infof("Stopped monitoring lease")
return errCanceled
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion subnet/etcdv2/mock_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (me *mockEtcd) sendEvent(resp *etcd.Response) {
me.events = append(me.events, resp)

// and notify watchers
for w, _ := range me.watchers {
for w := range me.watchers {
w.notifyEvent(resp)
}
}
Expand Down
4 changes: 4 additions & 0 deletions subnet/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func WatchLeases(ctx context.Context, sm Manager, ownLease *Lease, receiver chan
res, err := sm.WatchLeases(ctx, cursor)
if err != nil {
if err == context.Canceled || err == context.DeadlineExceeded {
log.Infof("%v, close receiver chan", err)
close(receiver)
return
}

Expand Down Expand Up @@ -169,6 +171,8 @@ func WatchLease(ctx context.Context, sm Manager, sn ip.IP4Net, receiver chan Eve
wr, err := sm.WatchLease(ctx, sn, cursor)
if err != nil {
if err == context.Canceled || err == context.DeadlineExceeded {
log.Infof("%v, close receiver chan", err)
close(receiver)
return
}

Expand Down

0 comments on commit 78035d0

Please sign in to comment.