more initial commits
This commit is contained in:
@ -768,16 +768,38 @@ func (t *http2Server) keepalive() {
|
|||||||
maxIdle := time.NewTimer(t.kp.MaxConnectionIdle)
|
maxIdle := time.NewTimer(t.kp.MaxConnectionIdle)
|
||||||
maxAge := time.NewTimer(t.kp.MaxConnectionAge)
|
maxAge := time.NewTimer(t.kp.MaxConnectionAge)
|
||||||
keepalive := time.NewTimer(t.kp.Time)
|
keepalive := time.NewTimer(t.kp.Time)
|
||||||
|
// NOTE: All exit paths of this function should reset their
|
||||||
|
// respecitve timers. A failure to do so will cause the
|
||||||
|
// following clean-up to deadlock and eventually leak.
|
||||||
|
defer func() {
|
||||||
|
if !maxIdle.Stop() {
|
||||||
|
<-maxIdle.C
|
||||||
|
}
|
||||||
|
if !maxAge.Stop() {
|
||||||
|
<-maxAge.C
|
||||||
|
}
|
||||||
|
if !keepalive.Stop() {
|
||||||
|
<-keepalive.C
|
||||||
|
}
|
||||||
|
}()
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
idle := t.idle
|
oidle := t.idle
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-maxIdle.C:
|
case <-maxIdle.C:
|
||||||
if idle == t.idle {
|
t.mu.Lock()
|
||||||
// send go away
|
idle := t.idle
|
||||||
|
t.mu.Unlock()
|
||||||
|
if idle == oidle {
|
||||||
|
t.Drain()
|
||||||
|
//TODO: Graceful connection termination!?
|
||||||
|
// Reseting the timer so that the clean-up doesn't deadlock.
|
||||||
|
maxIdle.Reset(infinity)
|
||||||
|
// New Stream might get created by the time GoAway is written on the wire.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
oidle = idle
|
||||||
if idle.IsZero() {
|
if idle.IsZero() {
|
||||||
maxIdle.Reset(t.kp.MaxConnectionIdle)
|
maxIdle.Reset(t.kp.MaxConnectionIdle)
|
||||||
continue
|
continue
|
||||||
@ -786,7 +808,6 @@ func (t *http2Server) keepalive() {
|
|||||||
case <-maxAge.C:
|
case <-maxAge.C:
|
||||||
case <-keepalive.C:
|
case <-keepalive.C:
|
||||||
case <-t.shutdownChan:
|
case <-t.shutdownChan:
|
||||||
// TODO(mmukhi): clean-up
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ func setUpWithNoPingServer(t *testing.T, copts ConnectOptions, done chan net.Con
|
|||||||
// MaxConnectionIdle time.
|
// MaxConnectionIdle time.
|
||||||
func TestMaxConnectionIdle(t *testing.T) {
|
func TestMaxConnectionIdle(t *testing.T) {
|
||||||
serverConfig := &ServerConfig{
|
serverConfig := &ServerConfig{
|
||||||
keepaliveParams: keepalive.ServerParams{
|
keepaliveParams: keepalive.ServerParameters{
|
||||||
MaxConnectionIdle: 2 * time.Second,
|
MaxConnectionIdle: 2 * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -317,8 +317,14 @@ func TestMaxConnectionIdle(t *testing.T) {
|
|||||||
stream.mu.Lock()
|
stream.mu.Lock()
|
||||||
stream.rstStream = true
|
stream.rstStream = true
|
||||||
stream.mu.Unlock()
|
stream.mu.Unlock()
|
||||||
client.CloseStream()
|
client.CloseStream(stream, nil)
|
||||||
// wait for server to see that closed stream and max age to send goaway after no new RPCs are mode
|
// wait for server to see that closed stream and max age to send goaway after no new RPCs are mode
|
||||||
|
timeout := time.NewTimer(time.Second * 4)
|
||||||
|
select {
|
||||||
|
case <-client.GoAway():
|
||||||
|
case <-timeout.C:
|
||||||
|
t.Fatalf("Test timed out, expected a GoAway from server")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKeepaliveClientClosesIdleTransport(t *testing.T) {
|
func TestKeepaliveClientClosesIdleTransport(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user