664 Commits

Author SHA1 Message Date
Jorropo
1d1ef93038 http2: use custom concurrent safe noBodyReader type when no body is present
Previously it used to use an empty bytes.Reader. However bytes.Reader is
concurrent safe when empty only on Read, that an issue now that io.NopCloser
forwards WriteTo.

Change-Id: Icdbd63876394b66ae8f3c8d410dc81a9b8dff33b
Reviewed-on: https://go-review.googlesource.com/c/net/+/401014
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-04-21 23:57:06 +00:00
Antonio Ojea
1850ba15e1 http2: make the Server use the priority write scheduler
make the Server use the priority write scheduler by default,
this way the defaults will be the same on stdlib and x/net.

xref: 8f36668178

Signed-off-by: Antonio Ojea <antonio.ojea.garcia@gmail.com>
Change-Id: Ibeed7a2bb8949d9bc5edb30fc723427f6cc157be
Reviewed-on: https://go-review.googlesource.com/c/net/+/382015
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-20 15:31:59 +00:00
Moshe Good
a630d4f3e7 http2: support concurrent Request.Close calls
While no guarantees are made about the safety of repeated or
concurrent closes of a request body, HTTP/1 request bodies are
concurrency-safe and HTTP/2 ones should be as well.

Fixes golang/go#51197

Change-Id: Id6527dc2932579cabc9cbe921c6e0b3b4a3d472c
Reviewed-on: https://go-review.googlesource.com/c/net/+/386495
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-18 20:11:49 +00:00
Russ Cox
290c469a71 all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: Iae68a9cd600060577271575e893ecb23bed1e509
Reviewed-on: https://go-review.googlesource.com/c/net/+/399599
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-12 02:06:05 +00:00
Bryan C. Mills
aac1ed45d8 http2: skip "write: broken pipe" failures in TestServer on OpenBSD
This failure mode has been observed on openbsd/mips64 and
openbsd/arm64.

I have not diagnosed the precise root cause, but I suspect a platform
bug — perhaps a bad interaction with the relatively weakly-ordered
memory models on these CPUs.

For golang/go#52208.

Change-Id: I0ab0285cc395d22742ced8f28d5c9c3280fcd1e3
Reviewed-on: https://go-review.googlesource.com/c/net/+/398794
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-07 22:48:26 +00:00
Alexander Yastrebov
749bd193bc net/http2: omit invalid header value from error message
Updates golang/go#43631

Change-Id: Iaacc875fecbdb76f4099d3eb3d67f7ec9d40c224
GitHub-Last-Rev: 3e22a9ea2f
GitHub-Pull-Request: golang/net#115
Reviewed-on: https://go-review.googlesource.com/c/net/+/355930
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Cherry Mui <cherryyz@google.com>
2022-04-03 10:30:23 +00:00
Damien Neil
543a649e0b http2: log pings and RoundTrip retries when http2debug=1
Change-Id: I3a7358db65ebc474712817a776d8468d0b09f0ab
Reviewed-on: https://go-review.googlesource.com/c/net/+/359914
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-01 15:49:27 +00:00
Damien Neil
27dd868942 http2: improve handling of slow-closing net.Conns
Closing a *tls.Conn can write to the network, blocking indefinitely.

Don't hold cc.mu while closing Conns. If closing a *tls.Conn takes too
long (arbitrarily set at 250ms), try to acquire the underlying net.Conn
(Go 1.18+) and close it instead.

Change-Id: Ib4e4a26595108eba9cd767231c727fd9412658b5
Reviewed-on: https://go-review.googlesource.com/c/net/+/359636
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
2022-02-25 17:22:49 +00:00
Bryan C. Mills
2ed6ce1e17 http2: in TestContentEncodingNoSniffing, do not allow the Transport to outlive the serverTester
This test constructed a new serverTester for each subtest, but reused
a Transport across all of the tests. I don't fully understand why, but
for some reason that occasionally led to "connection reset by peer"
failures when the port was reused.

Scoping the Transport to the lifetime of the serverTester seems to
resolve the errors: I tested with

	go test ./http2 -run=TestContentEncodingNoSniffing -httptest.serve=127.0.0.1:8080 -count=10000

and got lots of failures prior to this change and none after.

Fixes golang/go#46762
(I hope.)

Change-Id: I385c077c1d8627e42ce4d2db041878aacb5452fb
Reviewed-on: https://go-review.googlesource.com/c/net/+/380154
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-01-21 17:51:14 +00:00
Bryan C. Mills
0dd24b26b4 http2: eliminate arbitrary timeouts in readFrame methods
Certain slower builders empirically do not finish before these
timeouts, and if a real deadlock should occur it would be more useful
to let the test itself time out and get a goroutine dump anyway.

Fixes golang/go#50556
Fixes golang/go#34615

Change-Id: I53ea616faa34f4ccc73af8eb18b794e12271b883
Reviewed-on: https://go-review.googlesource.com/c/net/+/377814
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2022-01-14 01:14:07 +00:00
Ian Lance Taylor
4ddde0e984 http2: fix tipo in comment
Change-Id: I821714084436f4d16c9a26ea09d1bdc8e78ceddf
Reviewed-on: https://go-review.googlesource.com/c/net/+/372134
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-12-15 06:06:38 +00:00
Damien Neil
491a49abca http2: cap the size of the server's canonical header cache
The HTTP/2 server keeps a per-connection cache mapping header keys
to their canonicalized form (e.g., "foo-bar" => "Foo-Bar"). Cap the
maximum size of this cache to prevent a peer sending many unique
header keys from causing unbounded memory growth.

Cap chosen arbitrarily at 32 entries. Since this cache does not
include common headers (e.g., "content-type"), 32 seems like more
than enough for almost all normal uses.

Fixes #50058
Fixes CVE-2021-44716

Change-Id: Ia83696dc23253c12af8f26d502557c2cc9841105
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1290827
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/net/+/369794
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-09 12:49:13 +00:00
Damien Neil
db4efeb81f http2: deflake TestTransportGroupsPendingDials
This test makes assumptions about the internal structure of *clientConnPool,
as well as assuming that a goroutine will schedule and run within one
second. The former assumption isn't necessary, and the latter causes
flakiness.

Refactor the test to count dial and close calls, which is all it needs
to test the desired behavior (one pending dial per destination).

Fixes golang/go#43176.

Change-Id: I125b110f196e29f303960c6851089118f8fb5d38
Reviewed-on: https://go-review.googlesource.com/c/net/+/370175
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-08 01:23:54 +00:00
Antonio Ojea
04296fa82e http2: prioritize RST_STREAM frames in random write scheduler
The http2 random write scheduler should not queue RST_STREAM
frames with the DATA frames, and instead treat them as control frames.

There can be deadlock situations if data frames block the queue,
because if the sender wants to close the stream it sends an RST frame,
but if the client is not draining the queue, the RST frame is stuck
and the sender is not able to finish.

Fixes golang/go#49741

Change-Id: I0940a76d1aad95f1c4d3856e4d79cf5ce2a78ff2
Reviewed-on: https://go-review.googlesource.com/c/net/+/367154
Trust: Dave Cheney <dave@cheney.net>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-08 00:02:02 +00:00
Michal Hruby
0a0e4e1bb5 net/http2: Fix handling of expect continue
Recent refactoring in the http2 package broke handling of ExpectContinueTimeout, where the client was always waiting for the timeout to pass before sending the body.

Fixes: golang/go#49677

Change-Id: I565299e48313bb905b2655bd52084ea49ab742f3
GitHub-Last-Rev: 587b484079
GitHub-Pull-Request: golang/net#118
Reviewed-on: https://go-review.googlesource.com/c/net/+/363914
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
2021-12-01 19:05:59 +00:00
Damien Neil
6a13c67c3c http2: avoid spurious RoundTrip error when server closes and resets stream
Avoid a race condition between RoundTrip and the read loop when the
read loop reads a response followed by an immediate stream reset.

Fixes golang/go#49645

Change-Id: Ifb34e2dcb8cc443d3ff5d562cc032edf09da5307
Reviewed-on: https://go-review.googlesource.com/c/net/+/364834
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-18 16:13:19 +00:00
Damien Neil
47ca1ff314 http2: avoid busy loop when ResponseHeaderTimeout is set
Don't keep reading from respHeaderRecv after the response headers
are received.

Fixes golang/go#49615.

Change-Id: Ib8126c954930011ac09b2cbc70bbbce76531b7db
Reviewed-on: https://go-review.googlesource.com/c/net/+/364574
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-16 23:12:05 +00:00
Heschi Kreinick
e8b54dec6f http2/h2demo: delete
As discussed in golang/go#49301, the service has been shut down. Delete the
source.

Fixes golang/go#49301.

Change-Id: Id987c57d7007d9a75801d1a3a9a229fcd22d69e0
Reviewed-on: https://go-review.googlesource.com/c/net/+/364376
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-11-16 21:27:03 +00:00
Damien Neil
69e39bad7d http2: close conns after use when req.Close is set
Avoid reusing connections after receiving a response to a request
for which cc.Close is set or a "Connection: close" header is present.

Adjust the tests for connection reuse to test both the case where
new conns are created by the http2 package and when they are
created by the net/http package.

Fixes golang/go#49375

Change-Id: I58594972c832a20b66a3910c17acb51a98a9f7a5
Reviewed-on: https://go-review.googlesource.com/c/net/+/361498
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-12 20:21:33 +00:00
Damien Neil
f0573a1506 http2: avoid spurious context cancelation error from Response.Body.Close
When a request has a deadline set, the net/http package can cancel
the request context after reading an error (including io.EOF) from
the response body. Avoid returning a spurious error from
transportResponseBody if the request context is canceled.

For golang/go#49366.

Change-Id: I645466a1d6e405bdf17b3cc087204e4622a140eb
Reviewed-on: https://go-review.googlesource.com/c/net/+/362354
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-12 20:21:18 +00:00
Frank Chiarulli Jr
58aab5ef25 http2: compare Content-Encoding case-insensitive
RFC7230 states that Content-Encoding should be case insensitive, however the current http2 library only checks for lowercase, this PR checks for gzip using `EqualFold` as the http/1 library does. https://tools.ietf.org/html/rfc7230#section-4

Change-Id: Icfb8eb1e5a7ac2975ff3a06f40dbb5ccae8cd8cb
GitHub-Last-Rev: 61029e9fc8
GitHub-Pull-Request: golang/net#85
Reviewed-on: https://go-review.googlesource.com/c/net/+/259897
Trust: Meng Zhuo <mzh@golangcn.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Meng Zhuo <mzh@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-11 16:01:37 +00:00
Roland Shoemaker
6635138e15 http2: fix TLS1.0 and TLS1.1 rejection tests
Fixes golang/go#49442

Change-Id: Idb447aa5d33ba312ce28d8ed7f741be652075b4e
Reviewed-on: https://go-review.googlesource.com/c/net/+/362314
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-08 17:07:45 +00:00
Damien Neil
b53810dc28 http2: don't count aborted streams as active in tests
Deflake TestClientConnCloseAtBody, which assumes all streams
have been fully cleaned up after ClientConn.Close returns.
Only count active streams, not ones in the process of aborting.

Perhaps ClientConn.Close should block until all streams have
been cleaned up, although this could result in Close blocking
indefinitely if a stream is blocked reading from the request body.

Fixes golang/go#49335.

Change-Id: I172e0d3f10875191d29b24598de0abbdeb35e434
Reviewed-on: https://go-review.googlesource.com/c/net/+/361536
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-11-05 19:24:38 +00:00
Damien Neil
7594919abe http2: avoid race between processing END_STREAM and closing Response.Body
When the client gets an END_STREAM from the peer, it causes the
response body to return io.EOF and closes cs.peerClosed.

It is possible for the caller of RoundTrip to read io.EOF from the
response body and end the request by calling Response.Body.Close
before we close cs.peerClosed. In this case, we send a spurious
RST_STREAM to the peer.

Closing cs.peerClosed first reverses the race: This can cause the
response body to return "request canceled" rather than io.EOF.

Close both streams with the connection mutex held.

Fixes golang/go#49314

Change-Id: I75557670497c96dd6ed1b566bb4f0f3106a0c9f9
Reviewed-on: https://go-review.googlesource.com/c/net/+/361267
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-04 16:11:57 +00:00
Damien Neil
4a448f8816 http2: set ContentLength to -1 for HEAD response with no Content-Length
When reading a response to a HEAD request with no Content-Length,
set the Response ContentLength to -1 (unknown) rather than 0.

Fixes failing net/http TestH12_HeadContentLengthNoBody.

Change-Id: I472cbcf555e7f70bc41f58bf96da3d3c5bed9654
Reviewed-on: https://go-review.googlesource.com/c/net/+/360376
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-11-01 19:34:20 +00:00
Damien Neil
99673261e6 http2: set Response.ContentLength to 0 when headers end stream
When reading a response with no Content-Length and no body, set the
Response ContentLength to 0.

Fixes failing net/http TestH2_204NoBody and TestH2_304_NoBody tests.

Change-Id: I8ded6f8febfce62e00f2c37de65cbb09b306f7c6
Reviewed-on: https://go-review.googlesource.com/c/net/+/359834
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-29 22:46:45 +00:00
Damien Neil
540bb53d3b http2: add Transport.WriteByteTimeout
Add a Transport-level knob to set a timeout for writes to net.Conns.
If a write exceeds the timeout without making any progress (at least
one byte written), the connection is closed.

Fixes golang/go#48830.

Change-Id: If0f57996d11c92bced30e07d1e238cbf8994acb4
Reviewed-on: https://go-review.googlesource.com/c/net/+/354431
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-29 16:03:32 +00:00
Damien Neil
d418f374d3 http2: ignore read errors after closing the request body
We close the request body after receiving an error status code.
This is supposed to cause cs.writeRequestBody to return
errStopReqBodyWrite. Ensure that it does so if it gets an error
reading from the post-close body, rather than returning an
error which causes the entire request to be aborted.

Change-Id: I7c51928cb678f5baf37148f0df6ab196518d39d4
Reviewed-on: https://go-review.googlesource.com/c/net/+/356969
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-20 06:06:15 +00:00
Damien Neil
4f30a5c013 http2: deflake TestTransportRetriesOnStreamProtocolError
During this test:
  -> client sends req1
  <- server sends req1 headers
  -> client sends req2
  <- server resets req2
  <- server sends END_STREAM for req1
  -> client closes the *server* connection

The flake occurs when the last two steps happen out of order: The
client processes the reset for req2, returns from RoundTrip, and
the test closes the connection before the server writes the last
DATA frame for req1. This can be demonstrated by inserting a 1ms
sleep between WriteRSTStream and WriteData on the server side of
the test.

It isn't clear why the client side of the test is closing the server
side of the connection; it isn't essential to the test in any way.
Remove it.

Fixes golang/go#48994.

Change-Id: If074e45a76205ebd245617ef1b068967a6674b94
Reviewed-on: https://go-review.googlesource.com/c/net/+/356329
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-10-15 21:04:44 +00:00
Damien Neil
db2dff38ab http2: don't abort half-closed streams on server connection close
If the server sends an END_STREAM for a stream and then closes the
connection, allow the stream to complete normally.

Fixes golang/go#48995

Change-Id: Ia876e6e6e7eb4a0563db74c931c03a44620ece08
Reviewed-on: https://go-review.googlesource.com/c/net/+/356030
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-15 17:46:53 +00:00
Damien Neil
fd004c51d1 http2: on write errors, close ClientConn before returning from RoundTrip
Deflakes TestTransportRoundtripCloseOnWriteError.

Fixes golang/go#48995.

Change-Id: I4384d9091d55307d15fbd44b1b8137dcc8939c86
Reviewed-on: https://go-review.googlesource.com/c/net/+/356029
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-14 22:23:26 +00:00
Damien Neil
2b766c08f1 http2: deflake TestTransportReqBodyAfterResponse_200
Don't send the END_STREAM flag from the server until the client
sends its END_STREAM. Avoids a flaky failure when the client
sends the END_STREAM in a zero-length DATA frame:

  - The server reads bodySize bytes and half-closes the stream.
  - The client's Response.Body returns EOF.
  - The test calls Response.Body.Close.
  - The client resets the stream.

Avoid hanging forever on the client side of the test if the
server side exits with an error.

Fixes golang/go#48970

Change-Id: Ic921a3f60149abbb5434ec7a53985becea7b23c3
Reviewed-on: https://go-review.googlesource.com/c/net/+/355649
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-10-14 17:25:44 +00:00
Damien Neil
e13a2654a7 http2: close the Request's Body when aborting a stream
After RoundTrip returns, closing the Response's Body should
interrupt any ongoing write of the request body. Close the
Request's Body to unblock the body writer.

Take additional care around the use of a Request after
its Response's Body has been closed. The RoundTripper contract
permits the caller to modify the request after the Response's
body has been closed.

Updates golang/go#48908.

Change-Id: I261e08eb5d70016b49942d72833f46b2ae83962a
Reviewed-on: https://go-review.googlesource.com/c/net/+/355491
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-13 17:12:55 +00:00
renthraysk
ee2e9a0823 http2: number of allocs reduced from 3852 to 31
buildRootHuffmanNode() was allocating a new node for every leaf of the huffman decoding tree.
This PR allocates an array of nodes for all the leaf nodes, and reuses them.
As buildRootHuffmanNode is only called via sync.Once, it's not significant performance wise, but still seems an unnecessary number of allocations.

benchmark           old ns/op     new ns/op     delta
BenchmarkRoot-4     162847        17911         -89.00%

benchmark           old allocs     new allocs     delta
BenchmarkRoot-4     3852           31             -99.20%

benchmark           old bytes     new bytes     delta
BenchmarkRoot-4     92112         35056         -61.94%

Change-Id: I7c1eae13fb6130090610eec1eb0347d5d1fef20c
GitHub-Last-Rev: f40a4e8530
GitHub-Pull-Request: golang/net#112
Reviewed-on: https://go-review.googlesource.com/c/net/+/346649
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-13 15:36:59 +00:00
Alexander Yastrebov
08712a7432 http2: return unexpected eof on empty response with non-zero content length
Fixes golang/go#46071

Change-Id: I8b8262ba8e28a129f6aacfca43b7b8d9e605a0ce
GitHub-Last-Rev: 11b92cc8ba
GitHub-Pull-Request: golang/net#114
Reviewed-on: https://go-review.googlesource.com/c/net/+/354141
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-13 15:34:56 +00:00
Damien Neil
caeb26a5c8 http2: don't rely on system TCP buffer sizes in TestServer_MaxQueuedControlFrames
This test relies on filling up a TCP write buffer, but buffer sizes aren't
under our control and can be large. Use a net.Conn wrapper that blocks instead.

Change-Id: I72471ef293f906b33f2a0fd81d69a3dd57f32fde
Reviewed-on: https://go-review.googlesource.com/c/net/+/349932
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-11 17:04:08 +00:00
Brad Fitzpatrick
59d4e928ea http2: add ClientConnState, ClientConn.State accessor
So ClientConnPool can be implemented with the same functionality
as the built-in one. And for observability.

Change-Id: I855fbac3d9e4c02ab213a3e6a80b00f857648264
Reviewed-on: https://go-review.googlesource.com/c/net/+/354351
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-07 12:55:05 +00:00
Damien Neil
62292e8068 http2: detect write-blocked PING frames
We start the PingTimeout timer before writing a PING frame.
However, writing the frame can block indefinitely (either
acquiring cc.wmu or writing to the conn), and the timer is
not checked until after the frame is written.

Move PING writes into a separate goroutine, so we can detect
write-blocked connections.

Fixes golang/go#48810.

Change-Id: Ifd67fa23799e750d02754e1fe5d32719f60faed4
Reviewed-on: https://go-review.googlesource.com/c/net/+/354389
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-06 19:02:31 +00:00
Damien Neil
d2e5035098 http2: avoid race in TestTransportReqBodyAfterResponse_403.
This test sends a request with a 10MiB body, reads a 403 response
while the body is still being written, and closes the response body.
It then verifies that the full request body was not written, since
reading a response code >=300 interrupts body writes.

This can be racy: We process the status code and interrupt the body
write in RoundTrip, but it is possible for the body write to complete
before RoundTrip looks at the response.

Adjust the test to have more control over the request body:
Only provide half the Request.Body until after the response headers
have been received.

Fixes golang/go#48792.

Change-Id: Id4802b04a50f34f6af28f4eb93e37ef70a33a068
Reviewed-on: https://go-review.googlesource.com/c/net/+/354130
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-05 21:50:30 +00:00
Damien Neil
d4b1ae081e http2: avoid clientConnPool panic when NewClientConn fails
Change-Id: Id5c1c40f9d8a07b7e6d399cc4e9f60ebe10ccf49
Reviewed-on: https://go-review.googlesource.com/c/net/+/353881
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-05 00:13:12 +00:00
Damien Neil
69340ce214 http2: avoid extra GetConn trace call
CL 352469 inverts the case in shouldTraceGetConn: We want to call GetConn
for connections that have been previously used, but it calls GetConn
only on approximately the first use. "Approximately", because it uses
cc.nextStreamID to determine if the connection has been used, which
is racy.

Restructure the decision to call GetConn to track a per-ClientConn bool
indicating whether GetConn has already been called for this connection.
Set this bool for connections received from net/http, clear it after the
first use of the connection.

Fixes net/http's TestTransportEventTrace_h2.

Change-Id: I8e3dbba7cfbce9acd3612e39b6b6ee558bbfc864
Reviewed-on: https://go-review.googlesource.com/c/net/+/353875
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-04 22:05:34 +00:00
Damien Neil
b30845b58a http2: fix typo in doRequest doc comment
Change-Id: I46dc54abeb978a2458bbc41b471a8d9b6613cb0d
Reviewed-on: https://go-review.googlesource.com/c/net/+/353872
Trust: Damien Neil <dneil@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-04 19:50:52 +00:00
Damien Neil
cedda3a722 http2: refactor request write flow
Move the entire request write into a new writeRequest function,
which runs as its own goroutine.

The writeRequest function handles all indefintely-blocking
operations (in particular, network writes), as well as all
post-request cleanup: Closing the request body, sending a
RST_STREAM when necessary, releasing the concurrency slot
held by the stream, etc.

Consolidates several goroutines used to wait for stream
slots, write the body, and close response bodies.

Ensures that RoundTrip does not block past request cancelation.

Change-Id: Iaf8bb3e17de89384b031ec4f324918b5720f5877
Reviewed-on: https://go-review.googlesource.com/c/net/+/353390
Trust: Damien Neil <dneil@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-04 16:44:53 +00:00
Michael Fraenkel
e81a3d93ec http2: remove PingTimeout from TestTransportPingWhenReading
Use the default PingTimeout since it has no bearing on the test. A small
value can cause a failure on slower machines. Rely on the deadline to
determine a sufficient amount of time to complete.

Fixes golang/go#48668

Change-Id: I9389777fa00ed5193f1fc7ae04d2e2134114c675
Reviewed-on: https://go-review.googlesource.com/c/net/+/352970
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-29 19:35:57 +00:00
Brad Fitzpatrick
d455829e37 http2: add error counter to one missing processHeaders error path
And unrelated typo fix.

Updates golang/go#48675

Change-Id: Id90e0e76e514ba550fa2d3c9e1104ebfd4c23a9b
Reviewed-on: https://go-review.googlesource.com/c/net/+/353031
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
2021-09-29 16:15:16 +00:00
Brad Fitzpatrick
7d9f5e0b76 http2: wire up Transport and Server's CountError to frame parser code
So all frame parse errors are annotated and flow into the transport
or server's error counters.

Change-Id: I1e287fe33d422f97075029201976b009218852da
Reviewed-on: https://go-review.googlesource.com/c/net/+/352649
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2021-09-28 04:43:08 +00:00
Brad Fitzpatrick
4e4d966f74 http2: fix Transport connection pool TOCTOU max concurrent stream bug
Change-Id: I3e02072403f2f40ade4ef931058bbb5892776754
Reviewed-on: https://go-review.googlesource.com/c/net/+/352469
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
2021-09-27 18:15:40 +00:00
Brad Fitzpatrick
76eb614f96 http2: shut down idle Transport connections after protocol errors
Change-Id: Ic4e85cdc75b4baef7cd61a65b1b09f430a2ffc4b
Reviewed-on: https://go-review.googlesource.com/c/net/+/352449
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2021-09-27 16:17:02 +00:00
Damien Neil
3ad01bbaa1 http2: remove check for read-after-close of request bodies
Aborting a request currently races with writes of the request
body, so abortRequestBodyWrite can close the body before writeRequestBody
reads from it.

Fixes golang/go#48555.

Change-Id: I5362283f4066611aeecbc48b400d79cfa0b4b284
Reviewed-on: https://go-review.googlesource.com/c/net/+/351972
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-09-24 15:19:03 +00:00
Damien Neil
cf34111cab http: fix race in DATA frame padding refund
Move flow adjustment back under cc.mu.

Fixes golang/go#48491.

Change-Id: Idb762091cfeb55c18bc74389e62193f81438624f
Reviewed-on: https://go-review.googlesource.com/c/net/+/351950
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-09-24 05:40:57 +00:00