Skip to content

Commit

Permalink
avoid delaying the GotaFrame forever
Browse files Browse the repository at this point in the history
  • Loading branch information
jim3ma committed Sep 17, 2017
1 parent 28a0b8c commit 5da745c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
30 changes: 30 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ func (cm *ConnManager) dispatch() {
}
}()

newCCIDDelayCount := make(map[CCID]struct {
sleepNanosecond time.Duration
delayCount int
})
newCCIDMaxDelayCount := 100

for gf := range cm.readFromTunnelC {
Verbosef("CM: Received frame from tunnel: %s", gf)

Expand All @@ -439,6 +445,8 @@ func (cm *ConnManager) dispatch() {
case <-time.After(10 * time.Nanosecond):
log.Warnf("CM: Conn handler receive Gota Frame timeout: %s, delivery the Gota Frame async", gf)
go func(gf *GotaFrame, ch *ConnHandler) {
// TODO "send on closed channel" panic
defer Recover()
ch.ReadFromTunnelC <- gf
}(gf, ch)
}
Expand All @@ -448,6 +456,22 @@ func (cm *ConnManager) dispatch() {
// fast open feature
// TODO maybe a bug for multiple init seq num for fast open
if cm.fastOpen && !gf.IsControl() && gf.SeqNum == FastOpenInitSeqNum {
delay, ok := newCCIDDelayCount[NewCCID(gf.clientID, gf.ConnID)]
if !ok {
newCCIDDelayCount[NewCCID(gf.clientID, gf.ConnID)] = struct {
sleepNanosecond time.Duration
delayCount int
}{
FastOpenDelayNanosecond,
1,
}
delay = newCCIDDelayCount[NewCCID(gf.clientID, gf.ConnID)]
}
if delay.delayCount >= newCCIDMaxDelayCount {
log.Warnf("CM: Max delay count reached for Gota Frame: %s", gf)
continue
}

if cm.mode == ActiveMode {
log.Warnf("CM: ActiveMode should not receive this frame, may be a bug, Gota Frame: %s", gf)
continue
Expand All @@ -459,6 +483,12 @@ func (cm *ConnManager) dispatch() {
time.Sleep(FastOpenDelayNanosecond * time.Nanosecond)
cm.readFromTunnelC <- gf
}(gf)

delay.delayCount += 1
if delay.sleepNanosecond*time.Nanosecond < 8*time.Second {
delay.sleepNanosecond *= 2
}
newCCIDDelayCount[NewCCID(gf.clientID, gf.ConnID)] = delay
continue
}

Expand Down
9 changes: 7 additions & 2 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,13 @@ func (tm *TunnelManager) cleanUpReadPool() {
tm.poolLock.Lock()
rp, ok := tm.readPool[cid]
if ok {
gf := &GotaFrame{}
<-rp <- gf
go func(rp chan chan *GotaFrame) {
gf := &GotaFrame{}
select {
case <-rp <- gf:
case <-time.After(30 * time.Second):
}
}(rp)
/*
Loop:
for {
Expand Down

0 comments on commit 5da745c

Please sign in to comment.