Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Apr 12, 2024
1 parent b6fae38 commit 65ce7bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
7 changes: 4 additions & 3 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ func newHTTP2Client(connectCtx, ctx context.Context, addr resolver.Address, opts
go t.reader(readerErrCh)
defer func() {
if err != nil {
// writerDone should be closed since the loopy goroutine wouldn't have started in the case this function returns an error.
// writerDone should be closed since the loopy goroutine
// wouldn't have started in the case this function returns an error.
close(t.writerDone)
t.Close(err)
}
Expand Down Expand Up @@ -523,7 +524,7 @@ func (t *http2Client) getPeer() *peer.Peer {
// OutgoingGoAwayHandler writes a GOAWAY to the connection. Always returns (false, err) as we want the GoAway
// to be the last frame loopy writes to the transport.
func (t *http2Client) outgoingGoAwayHandler(g *goAway) (bool, error) {
if err := t.framer.fr.WriteGoAway(math.MaxUint32, http2.ErrCodeNo, g.debugData); err != nil {
if err := t.framer.fr.WriteGoAway(math.MaxInt32*3/4, http2.ErrCodeNo, g.debugData); err != nil {
return false, err
}
return false, g.closeConn
Expand Down Expand Up @@ -1005,7 +1006,7 @@ func (t *http2Client) Close(err error) {
t.mu.Unlock()
// Per HTTP/2 spec, a GOAWAY frame must be sent before closing the
// connection. See https://httpwg.org/specs/rfc7540.html#GOAWAY.
t.controlBuf.put(&goAway{code: http2.ErrCodeNo, debugData: []byte(fmt.Sprintf("client shutdown with: %v", err)), closeConn: err})
t.controlBuf.put(&goAway{code: http2.ErrCodeNo, debugData: []byte(err.Error()), closeConn: err})
<-t.writerDone
t.cancel()
t.conn.Close()
Expand Down
16 changes: 6 additions & 10 deletions internal/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2723,14 +2723,12 @@ func (s) TestClientSendsAGoAwayFrame(t *testing.T) {
t.Logf("Received goAway frame from client")
close(errorCh)
} else {
t.Logf("Received unexpected goAway frame from client")
errorCh <- errors.New("received unexpected goAway frame from client")
errorCh <- fmt.Errorf("received unexpected goAway frame: %v", err)
close(errorCh)
}
return
default:
t.Logf("The server received a frame other than GOAWAY")
errorCh <- errors.New("server received a frame other than GOAWAY")
errorCh <- fmt.Errorf("server received a frame other than GOAWAY: %v", err)
close(errorCh)
return
}
Expand All @@ -2750,12 +2748,10 @@ func (s) TestClientSendsAGoAwayFrame(t *testing.T) {
t.Logf("Closed the client connection")
select {
case err = <-errorCh:
if err != nil {
t.Errorf("Error receiving the GOAWAY frame: %v", err)
}
case <-ctx.Done():
t.Errorf("Timed out")
}
if err != nil {
t.Errorf("Error receiving the GOAWAY frame: %v", err)
} else {
t.Logf("Received a GOAWAY frame from client")
t.Errorf("Context timed out")
}
}
6 changes: 4 additions & 2 deletions test/goaway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package test

import (
"context"
"fmt"
"io"
"net"
"strings"
Expand Down Expand Up @@ -794,7 +795,7 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
}
ct := val.(*clientTester)
goAwayReceived := make(chan struct{})
errCh := make(chan struct{})
errCh := make(chan error)
go func() {
for {
f, err := ct.fr.ReadFrame()
Expand All @@ -810,6 +811,7 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
}
default:
t.Errorf("server tester received unexpected frame type %T", f)
errCh <- fmt.Errorf("server tester received unexpected frame type %T", f)
close(errCh)
}
}
Expand All @@ -818,7 +820,7 @@ func (s) TestClientSendsAGoAway(t *testing.T) {
defer ct.conn.Close()
select {
case <-goAwayReceived:
case <-errCh:
case err = <-errCh:
t.Errorf("Error receiving the goAway: %v", err)
case <-ctx.Done():
t.Errorf("Context timed out")
Expand Down

0 comments on commit 65ce7bd

Please sign in to comment.