MCPcopy
hub / github.com/grpc/grpc-go / TestClientSettingsFloodCloseConn

Method TestClientSettingsFloodCloseConn

test/end2end_test.go:6574–6643  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6572}
6573
6574func (s) TestClientSettingsFloodCloseConn(t *testing.T) {
6575 // Tests that the server properly closes its transport if the client floods
6576 // settings frames and then closes the connection.
6577
6578 // Minimize buffer sizes to stimulate failure condition more quickly.
6579 s := grpc.NewServer(grpc.WriteBufferSize(20))
6580 l := bufconn.Listen(20)
6581 go s.Serve(l)
6582
6583 // Dial our server and handshake.
6584 conn, err := l.Dial()
6585 if err != nil {
6586 t.Fatalf("Error dialing bufconn: %v", err)
6587 }
6588
6589 n, err := conn.Write([]byte(http2.ClientPreface))
6590 if err != nil || n != len(http2.ClientPreface) {
6591 t.Fatalf("Error writing client preface: %v, %v", n, err)
6592 }
6593
6594 fr := http2.NewFramer(conn, conn)
6595 f, err := fr.ReadFrame()
6596 if err != nil {
6597 t.Fatalf("Error reading initial settings frame: %v", err)
6598 }
6599 if _, ok := f.(*http2.SettingsFrame); ok {
6600 if err := fr.WriteSettingsAck(); err != nil {
6601 t.Fatalf("Error writing settings ack: %v", err)
6602 }
6603 } else {
6604 t.Fatalf("Error reading initial settings frame: type=%T", f)
6605 }
6606
6607 // Confirm settings can be written, and that an ack is read.
6608 if err = fr.WriteSettings(); err != nil {
6609 t.Fatalf("Error writing settings frame: %v", err)
6610 }
6611 if f, err = fr.ReadFrame(); err != nil {
6612 t.Fatalf("Error reading frame: %v", err)
6613 }
6614 if sf, ok := f.(*http2.SettingsFrame); !ok || !sf.IsAck() {
6615 t.Fatalf("Unexpected frame: %v", f)
6616 }
6617
6618 // Flood settings frames until a timeout occurs, indicating the server has
6619 // stopped reading from the connection, then close the conn.
6620 for {
6621 conn.SetWriteDeadline(time.Now().Add(50 * time.Millisecond))
6622 if err := fr.WriteSettings(); err != nil {
6623 if to, ok := err.(interface{ Timeout() bool }); !ok || !to.Timeout() {
6624 t.Fatalf("Received unexpected write error: %v", err)
6625 }
6626 break
6627 }
6628 }
6629 conn.Close()
6630
6631 // If the server does not handle this situation correctly, it will never

Callers

nothing calls this directly

Calls 15

NewServerFunction · 0.92
WriteBufferSizeFunction · 0.92
ListenFunction · 0.92
NowMethod · 0.80
TimeoutMethod · 0.80
ServeMethod · 0.65
FatalfMethod · 0.65
WriteMethod · 0.65
AddMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected