Commit Graph

2241 Commits

Author SHA1 Message Date
Alexander Yastrebov
4d04dc93f3 http2: pool transport gzip readers
This is a copy of the CL 510255 with the difference
that it preserves use of fs.ErrClosed when reading after close.

goos: darwin
goarch: arm64
pkg: golang.org/x/net/http2
cpu: Apple M4
              │   HEAD~1    │             HEAD              │
              │   sec/op    │   sec/op     vs base          │
ClientGzip-10   752.8µ ± 1%   750.7µ ± 2%  ~ (p=0.393 n=10)

              │    HEAD~1    │                 HEAD                 │
              │     B/op     │     B/op      vs base                │
ClientGzip-10   75.49Ki ± 0%   33.98Ki ± 3%  -54.99% (p=0.000 n=10)

              │   HEAD~1   │               HEAD                │
              │ allocs/op  │ allocs/op   vs base               │
ClientGzip-10   705.0 ± 0%   698.5 ± 0%  -0.92% (p=0.000 n=10)

Updates golang/go#61353
2025-10-10 14:41:04 +02:00
Alexander Yastrebov
32b70f4aae http2: add transport gzip response benchmark
For golang/go#61353
2025-10-10 14:38:03 +02:00
Damien Neil
9f2f0b95b6 http2: avoid data race on DebugGoroutines in TestGoroutineLock
TestGoroutineLock sets DebugGoroutines = true.

When a previous test leaves a server running after exiting,
this write to DebugGoroutines can race with reads from the server.
Obviously tests shouldn't leave goroutines around after they exit,
but it happens and when it does it can show up here as a rare
and hard-to-debug flake.

DebugGoroutines is always true in tests, so there's no need to set
it here. Just leave it alone.

Fixes golang/go#75811

Change-Id: Iebeab2a22642cbd6867b9f4f5a171c91ea697b17
Reviewed-on: https://go-review.googlesource.com/c/net/+/710675
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-10-09 10:59:46 -07:00
Nicholas S. Husin
e7c005de60 http2: implement a more efficient writeQueue that avoids unnecessary copies.
Our previous implementation of writeQueue relies on one
[]FrameWriteRequests, forcing us to copy the rest of the slice's content
whenever we remove an item from the front.

This change remedies this problem by implementing writeQueue using
two-stage queues, similar to Okasaki's purely functional queue.

With 25 frames per stream, we are observing the following performance
improvement:
goos: linux
goarch: amd64
pkg: golang.org/x/net/http2
cpu: AMD EPYC 7B13
              │  /tmp/old   │              /tmp/new               │
              │   sec/op    │   sec/op     vs base                │
WriteQueue-64   508.3n ± 3%   305.7n ± 3%  -39.86% (p=0.000 n=10)

              │  /tmp/old  │            /tmp/new            │
              │    B/op    │    B/op     vs base            │
WriteQueue-64   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

              │  /tmp/old  │            /tmp/new            │
              │ allocs/op  │ allocs/op   vs base            │
WriteQueue-64   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

As the number of frames increases, the performance difference becomes
more stark as the old implementation does a quadratic amount of copying
in total to be able to fully consume a queue.

Change-Id: Ide816ebdd89a41275b5829683c0f10d48321af50
Reviewed-on: https://go-review.googlesource.com/c/net/+/710635
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-10-09 10:55:28 -07:00
cuishuang
b93acc2126 all: use reflect.TypeFor instead of reflect.TypeOf
For golang/go#60088.

Change-Id: Ifc6d5cf0b94b977b2699e4781875bf75b9aa25c8
Reviewed-on: https://go-review.googlesource.com/c/net/+/709195
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-08 13:54:30 -07:00
Gopher Robot
2002a064a4 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: I2715ca45bf0dbe31bf912ab365632cb80be544ca
Reviewed-on: https://go-review.googlesource.com/c/net/+/710079
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
v0.46.0
2025-10-08 12:18:16 -07:00
Roland Shoemaker
59706cdaa8 html: impose open element stack size limit
The HTML specification contains a number of algorithms which are
quadratic in complexity by design. Instead of adding complicated
workarounds to prevent these cases from becoming extremely expensive in
pathological cases, we impose a limit of 512 to the size of the stack of
open elements. It is extremely unlikely that non-adversarial HTML
documents will ever hit this limit (but if we see cases of this, we may
want to make the limit configurable via a ParseOption).

Thanks to Guido Vranken and Jakub Ciolek for both independently
reporting this issue.

Fixes CVE-2025-47911
Fixes golang/go#75682

Change-Id: I890517b189af4ffbf427d25d3fde7ad7ec3509ad
Reviewed-on: https://go-review.googlesource.com/c/net/+/709876
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
v0.45.0
2025-10-07 11:18:01 -07:00
Roland Shoemaker
6ec8895aa5 html: align in row insertion mode with spec
Update inRowIM to match the HTML specification. This fixes an issue
where a specific HTML document could cause the parser to enter an
infinite loop when trying to parse a </tbody> and implied </tr> next to
each other.

Fixes CVE-2025-58190
Fixes golang/go#70179

Change-Id: Idcb133c87c7d475cc8c7eb1f1550ea21d8bdddea
Reviewed-on: https://go-review.googlesource.com/c/net/+/709875
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-07 11:17:53 -07:00
Nicholas S. Husin
539356380d http2: fix RFC 9218 write scheduler not being idempotent
Previously, the RFC 9218 write scheduler had a bug where AdjustStream()
did not update the stream's metadata after adjusting its priority. This
results in the function not being idempotent, where repeated calls to it
for the same stream can instead remove an unrelated stream from our
scheduler, and duplicate the stream whose priority is being updated.

For go/golang#75500

Change-Id: Iaf3dd819d02839bc6cff65027c4916f9f2fa3e5b
Reviewed-on: https://go-review.googlesource.com/c/net/+/709477
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-07 09:12:30 -07:00
Nicholas S. Husin
b2ab3712bc internal/httpsfv: implement parsing support for date and display string
This change adds support for parsing date and display string, meaning
this package can now fully parse any HTTP SFV that is compliant with
RFC 9651.

This package is still intended only for internal use at this point.

For golang/go#75500

Change-Id: I07626b45f01e0c5cb4e92aa3fea04cc7e2d0c814
Reviewed-on: https://go-review.googlesource.com/c/net/+/708437
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-02 12:44:41 -07:00
Nicholas S. Husin
edb764c229 internal/httpsfv: add parsing functionality for types defined in RFC 8941
This change introduces parsing functions for all item types defined in
RFC 8941, namely: integers, decimals, strings, tokens, byte sequences,
and booleans.

At this point, internal/httpsfv should be usable for parsing any RFC
8941-compliant HTTP Structured Field Values.

In a future CL, we will add support for parsing display strings and
dates, so that this package fully supports RFC 9651.

For golang/go#75500

Change-Id: Ib8ad2caa5f6ea4285d00506faa4b8127c2cc9419
Reviewed-on: https://go-review.googlesource.com/c/net/+/708435
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-01 18:54:45 -07:00
Nicholas S. Husin
fbba2c22cb internal/httpsfv: add support for consuming Display String and Date type
This CL adds consumeDisplayString() and consumeDate() function, meaning
that we can now consume all types that are defined within RFC 9651. In
future CL, we will add the corresponding parsing function for all the
types, so callers of this package will not have to implement their own
parsing / formatting.

For golang/go#75500

Change-Id: I90aa132d3ab1385b310d821997da13a095cd71bc
Reviewed-on: https://go-review.googlesource.com/c/net/+/708015
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-10-01 14:45:17 -07:00
Damien Neil
47a241fc51 http2: make the error channel pool per-Server
Channels can't be shared across synctest bubbles, so a global pool causes
panics when using an http2.Server in a bubble. Make the pool per-Server.
A Server can't be shared across bubbles anyway (it contains channels)
and outside of tests most programs will have a single Server.

Fixes golang/go#75674

Change-Id: I966f985e1b9644bdf8ae81d9abb142d80320cc82
Reviewed-on: https://go-review.googlesource.com/c/net/+/708135
Auto-Submit: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-10-01 09:50:47 -07:00
cuishuang
51f657b16c webdav/internal/xml: use the built-in min function
Starting from Go 1.21, the min functions are built-in.

Therefore, we can remove the custom functions with the same name.

Change-Id: Ia13e609358e19cf3863edc0f5a34e737cdcc291f
Reviewed-on: https://go-review.googlesource.com/c/net/+/707555
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
2025-09-30 12:18:58 -07:00
Nicholas S. Husin
f2e909b982 internal/httpsfv: implement parsing support for Dictionary and List type.
This change implements the Parse functions for the Dictionary and List
type. At this point, we should be able to use internal/httpsfv package
to extract information from any HTTP SFV that follows RFC 8941.

In future changes, we will add additional types introduced in RFC 9651
to achieve feature parity with it. Additionally, we will add Parse
functions for all the HTTP SFV types, such that users of the package do
not need to do their own type assertions and conversions.

Note that the Dictionary and List type do not have a consume function.
This is because both types never appear as a child of other types,
meaning it is guaranteed to always consume its entire string input.

For go/golang#75500

Change-Id: I376dca274d920a4bea276ebb4d49a9cd768c79fe
Reviewed-on: https://go-review.googlesource.com/c/net/+/707100
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-09-29 09:35:41 -07:00
Nicholas S. Husin
7d8cfcee6c internal/httpsfv: add support for Bare Inner List and Item type.
This change implements the consume and Parse functions for both the Item
and Bare Inner List type. This is part of a chain of changes that is needed
in order for us to fully support HTTP Structured Field Values parsing as
defined in RFC 9651.

In future changes, we will utilize the support for Bare Inner List and Item
that is added here to support more complex types, namely Dictionary and
List.

Note that Bare Inner List is something we define on our own. We define a
Bare Inner List as an Inner List without the top-most parameter meant
for the Inner List. For example, the Inner List `(a;b c;d);e` would
translate to the Bare Inner List `(a;b c;d)`. We have done this because
the parameter of an Inner List will be exposed to the user via
ParseDictionary() or ParseList() too. By implementing Bare Inner List,
we can avoid having two ways of accessing the Inner List parameter, and
incurring the cost of a more complex implementation for Inner List and
other types that utilize Inner List (e.g. if we have consumeInnerList,
ParseDictionary will have to use consumeInnerList and backtrack the
consumption to separate out the InnerList parameter).

For go/golang#75500

Change-Id: I9b418d10b5755195d1cc3ff5f7ea211423bc4b48
Reviewed-on: https://go-review.googlesource.com/c/net/+/707099
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-29 09:35:27 -07:00
Damien Neil
fe9bcbcc92 http2: support HTTP2Config.StrictMaxConcurrentRequests
When HTTP2Config.StrictMaxConcurrentRequests is set
(added in Go 1.26), use it to override the value of
Transport.StrictMaxConcurrentStreams.

Permits configuring this parameter from net/http
without importing x/net/http2.

For golang/go#67813

Change-Id: Ie7fa5a8ac033b1827cf7fef4e23b5110a05dc95f
Reviewed-on: https://go-review.googlesource.com/c/net/+/707315
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-09-29 09:34:56 -07:00
Nicholas S. Husin
c492e3c189 internal/httpsfv: add functionality to walk Parameters in HTTP SFV.
This change implements the minimum set of functionality within RFC 8491
that is needed in order for us to be able to extract information out of
Parameters type.

Rather than parsing the given Structured Field Values as usual, we
instead allow users to give us functions that will be invoked as we walk
through the SFV. This allows users to still extract information out of
SFV, without incurring significant memory allocation, especially when
the input is large.

If the current API & approach is good, we will proceed further by
implementing walk functionality for the rest of the types within RFC
8491: Dictionary, List, Item, and Inner List. After that, we will also
add support for Date and Display String to fully support RFC 9651.

For golang/go#75500

Change-Id: I838a7267a54fcd64b019be0ac10fe86b1e3e2c8b
Reviewed-on: https://go-review.googlesource.com/c/net/+/706755
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-25 13:52:30 -07:00
Nicholas S. Husin
10342476f5 http2: introduce a new write scheduler based on RFC 9218 priority scheme
This change introduces a new write scheduler that prioritizes writes
based on RFC 9218. Eventually, this scheduler will be used to replace
the existing priority scheduler based on RFC 7540, which has been
deprecated in RFC 9113.

No behavioral changes has been introduced as this scheduler is not used
anywhere yet.

goos: linux
goarch: amd64
pkg: golang.org/x/net/http2
cpu: AMD EPYC 7B13
BenchmarkWriteSchedulerThroughputRoundRobin-64                            100000            140884 ns/op          139201 B/op       2900 allocs/op
BenchmarkWriteSchedulerLifetimeRoundRobin-64                              100000            149632 ns/op          139202 B/op       2900 allocs/op
BenchmarkWriteSchedulerThroughputRandom-64                                100000            218311 ns/op          139201 B/op       2900 allocs/op
BenchmarkWriteSchedulerLifetimeRandom-64                                  100000            216559 ns/op          139203 B/op       2900 allocs/op
BenchmarkWriteSchedulerThroughputPriorityRFC7540-64                       100000            587625 ns/op          139201 B/op       2900 allocs/op
BenchmarkWriteSchedulerThroughputPriorityRFC9218Incremental-64            100000            149563 ns/op          139200 B/op       2900 allocs/op
BenchmarkWriteSchedulerLifetimePriorityRFC9218Incremental-64              100000            163697 ns/op          139201 B/op       2900 allocs/op
BenchmarkWriteSchedulerThroughputPriorityRFC9218NonIncremental-64         100000            145364 ns/op          139201 B/op       2900 allocs/op
BenchmarkWriteSchedulerLifetimePriorityRFC9218NonIncremental-64           100000            159316 ns/op          139203 B/op       2900 allocs/op

For golang/go#75500

Change-Id: Id5db195f6f75970f9cc3c7b7a292df96a139de8b
Reviewed-on: https://go-review.googlesource.com/c/net/+/704758
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-09-19 14:13:39 -07:00
Nicholas S. Husin
653f4f665b http2: disambiguate the existing priority WriteScheduler.
This change renames the file for the RFC 7540 priority write scheduler
to writesched_priority_rfc7540.go file. Existing symbols have also been
renamed to make it explicit that they are only used for the RFC 7540
priority implementation.

This is done so that when we introduce the new RFC 9218 priority write
scheduler, we will not cause confusion with regards to which symbols are
used for which scheduler.

This CL only renames and moves symbols, no behavior changes have been
introduced.

For golang/go#75500

Change-Id: I5c31bd51bc0d25415ff72909cc0b8f9fef44c052
Reviewed-on: https://go-review.googlesource.com/c/net/+/704757
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-18 13:27:35 -07:00
cuishuang
875d966983 all: fix some comments
Including mismatched function names/struct names, repeated words, typos, etc.

Change-Id: Ia576274bce6e6fbfe4d2fca6dcd6d31bf00936fb
Reviewed-on: https://go-review.googlesource.com/c/net/+/683875
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
2025-09-15 17:28:39 -07:00
Damien Neil
3b23d576ea http2: fix race condition when disabling goroutine debugging for one test
Fixes golang/go#66519

Change-Id: I7aecf20db44caaaf49754d62db193b8c42f3c63a
Reviewed-on: https://go-review.googlesource.com/c/net/+/701836
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
v0.44.0
2025-09-08 20:33:21 -07:00
Damien Neil
87410502ff http2: simplify TestServer_Push_RejectAfterGoAway
Replace bespoke test synchronization with a call to synctest.Wait.

Change-Id: Id082fbd3696b5b4a1839b2804ee61bb02e86a929
Reviewed-on: https://go-review.googlesource.com/c/net/+/701835
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-08 13:55:56 -07:00
Damien Neil
96e405cac1 http2: modernize TestTransportRoundtripCloseOnWriteError
Rewrite this test to use a testClientConn and fake network,
allowing us to inject its network error into the fake net
rather than by twiddling the client connection internals.

Change-Id: Idcd96498ceaee701ad0c053dc0c6ce74701cc182
Reviewed-on: https://go-review.googlesource.com/c/net/+/701006
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-08 13:55:53 -07:00
Damien Neil
6dc6880bcd http2: simplify ClientConn Close and Shutdown tests
Split testClientConnClose into four separate tests,
rather than having one big function which performs
different tests depending on its parameter.

Use the more modern testClientConn in these tests,
for simplicity.

Drop the activeStreams function, which pokes a bit too
far into implementation internals and isn't necessary
for the new tests. (It had one use outside of
testClientConnClose, which provides little useful
signal and can also be dropped.)

Change-Id: Id8d1c7feab59c1f041bc2d1cf0398e8b1e230c69
Reviewed-on: https://go-review.googlesource.com/c/net/+/701005
Reviewed-by: Nicholas Husin <nsh@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-08 13:53:19 -07:00
Damien Neil
4e2915b652 http2: modernize TestTransportAllocationsAfterResponseBodyClose
This is a transport test. Use a testClientConn rather than a
Transport attached to a test server, for better control over
the frames sent to the test transport.

Drop one section of the test which pokes into the response
body's transportResponseBody type, as being too coupled to the
implementation internals.

Change-Id: I7bc7c7c756fd0c596424fab9a892dda8d9e89d1c
Reviewed-on: https://go-review.googlesource.com/c/net/+/701004
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-08 13:53:16 -07:00
Damien Neil
30b0e78859 http2: modernize TestRoundTripDoesntConsumeRequestBodyEarly
Use a testClientConn with its fake network connection
configured to encounter an error, rather than an http2.Client
with its internals tweaked into a closed state.

Change-Id: I0e9415ca3fdf50b9d6cdaccb24d7c4939b3b6ebd
Reviewed-on: https://go-review.googlesource.com/c/net/+/701003
Reviewed-by: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-09-08 13:42:40 -07:00
Damien Neil
b9acd777f1 http2: speed up TestTransportFlowControl
Rewrite the slowest test in the http2 package.

This test was added in CL 23812 to verify that a Transport does not
provide flow control window updates until the user consumes data
from a stream.

Rewrite the test to use the more modern testClientConn, which permits
precise examination of when the transport sends WINDOW_UPDATE frames.

Change-Id: Ibcde492549cad6363ce0e1a5ba169da7a4427d85
Reviewed-on: https://go-review.googlesource.com/c/net/+/700923
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-09-08 13:42:37 -07:00
Gopher Robot
5153f4db31 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: I09a366e7b45776e22f3107e24584d1332a83543f
Reviewed-on: https://go-review.googlesource.com/c/net/+/701735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2025-09-08 11:55:48 -07:00
Damien Neil
9338bdd9ee http2: speed up TestTransportHandlerBodyClose
Rewrite the slowest test in the http2 package.

This test was added in CL 23287 to verify two changes:
  - A server handler calling req.Body.Close does not
    kill the request stream.
  - A Transport does not leak a goroutine if a request body is
    still being written when the request stream is closed.

Split the test into two individual tests, one for the
server behavior and one for the transport.

Change-Id: I211f458e1001df435d00c2e1ebd7f3072e053c89
Reviewed-on: https://go-review.googlesource.com/c/net/+/700922
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-08 11:02:39 -07:00
Damien Neil
6b200364a6 http2: add synchronous handler support to serverTester
It is often useful in server tests to orchestrate a sequence
of actions that involve both a server connection and request handler.
For example, we might want to have the request handler read from
the request body at a precise point in the test.

Add support for this to serverTester (used for most server tests).
Pass a nil handler to serverTester, and it will provide synchronous
access to the handler:

    call := st.nextHandlerCall()
    call.do(func(w http.ResponseWriter, r *http.Request) {
        // this executes in the handler goroutine
    })

Replace the existing handlerPuppet type, which provided a
similar mechanism but only worked on a single call at a time.

Change-Id: I023e032084f911ab4f9b803c393e4a55b12af87f
Reviewed-on: https://go-review.googlesource.com/c/net/+/701002
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-09-08 09:35:58 -07:00
Damien Neil
b0013c645b http2: modernize TestTransportChecksRequestHeaderListSize
Rewrite this test to use testClientConn, which simplifies tests
of client-only functionality.

Change-Id: I9ff86ef1267323caf6e085fe140f6d4641740328
Reviewed-on: https://go-review.googlesource.com/c/net/+/700921
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2025-09-08 07:15:58 -07:00
Damien Neil
162ad308ad http2: simplify TestServerWindowUpdateOnBodyClose
This test closes a handler's request mid-test by poking into
the server internals. There's no reason I can see to do this,
when the handler can just call req.Body.Close to achieve the
same effect.

Change the test to use the public API.

Change-Id: I4f14939e951c4d8f07abd9d3c2f30c2004f87dad
Reviewed-on: https://go-review.googlesource.com/c/net/+/701001
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2025-09-08 07:14:56 -07:00
Damien Neil
22a8c02e92 http2: remove test-only path in requestBody.Read
requestBody.Read avoids panicking when requestBody.conn is unset
and we are in tests. This seems like an excellent way to hide a
non-test panic. Drop the exceptional path.

This path was introduced in golang.org/cl/31636 to support a
test verifying that concurrently closing and reading from a
Request.Body does not race. Rewrite this test to use a real
server handler.

Change-Id: I778e78ff9ab45e248769557fff94d17940eb7a18
Reviewed-on: https://go-review.googlesource.com/c/net/+/701000
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-09-08 07:14:52 -07:00
Damien Neil
1ff92d3eb0 http2: don't panic when ServeConn is passed a nil options
Fixes golang/go#75286

Change-Id: I91e6a0a61234c81f809b74151946dddde9099078
Reviewed-on: https://go-review.googlesource.com/c/net/+/700999
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2025-09-05 13:18:06 -07:00
Damien Neil
a2a62f206b http2: use synctest.Wait rather than poking into server internals in test
Reduce test's dependence on unrelated internal implementation details.

Change-Id: Iaf38df44c1c8898cd8ab24587e410d45a48ef322
Reviewed-on: https://go-review.googlesource.com/c/net/+/700998
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2025-09-05 13:18:03 -07:00
Damien Neil
7da929c666 http2: avoid examining ResponseWriter internals in test
TestServer_Rejects_Too_Many_Streams digs inside a ResponseWriter
to find the stream ID for a request. Just pass the stream ID as
part of the request path to reduce coupling between the test
and package internals.

Change-Id: I4276a6c4497aa0f311f9227e3a26717eeecf95cb
Reviewed-on: https://go-review.googlesource.com/c/net/+/700997
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2025-09-05 13:17:59 -07:00
Damien Neil
a99f4fee59 http2: remove unused stream-level flow control check
The test-only function serverTester.wantFlowControlConsumed
purports to check for the amount of connection or stream level
flow control consumed. Calling it with a streamID of 0
checks the connection-level flow control tokens.

However, the stream-level flow control path is unimplemented and unused.
Calling this function with a non-zero streamID doesn't work,
and (fortunately) all tests that use it only check connection-level
flow control.

Rename the function to wantConnFlowControlConsumed.

Change-Id: I1d934e8b46b4c43d393d102f1b2621329a7472aa
Reviewed-on: https://go-review.googlesource.com/c/net/+/700920
Auto-Submit: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-09-05 11:17:01 -07:00
Damien Neil
2378062003 http2: remove pre-go1.24 support
The x/net go.mod requires go1.24. Remove support for older versions
which don't include the Server.HTTP2 and Transport.HTTP2 config fields.

Change-Id: I6498aa89270a2c58635424ff3e763c806666010e
Reviewed-on: https://go-review.googlesource.com/c/net/+/700919
Auto-Submit: Nicholas Husin <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-09-05 11:15:48 -07:00
Damien Neil
7c51e1fbce http2: use testing/synctest
Replace ad-hoc pre-synctest synchronization with testing/synctest.

Many of the http2 package tests use a custom-built fake time
implementation and a idleness-detection mechanism based on parsing
goroutine stack dumps. Experience with this approach to testing
eventually led to the development of the testing/synctest package.
Switch over to testing/synctest.

The synctest package became available as an experiment in Go 1.24
(only when GOEXPERIMENT=synctest is set), and was fully released
with some API changes in Go 1.25.

- Use the released synctest API on Go 1.25.

- Use the experimental API (synctest.Run) on Go 1.24 when
  GOEXPERIMENT=synctest is set. (Note that we set this on trybots.)

- Skip tests on Go 1.24 when GOEXPERIMENT=synctest is not set.

The x/net module requires go1.24, so older versions
can be disregarded.

Change-Id: Ifc13bfdd9bdada6c016730a78bd5972a5193ee30
Reviewed-on: https://go-review.googlesource.com/c/net/+/700996
Reviewed-by: Nicholas Husin <husin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-09-05 11:08:28 -07:00
Alan Donovan
b800b2045a context: add //go:fix inline annotation to Context et al
Updates golang/go#73605

Change-Id: Ib9d23a2eaa35f6099e6e42857b35f717a0a2f00d
Reviewed-on: https://go-review.googlesource.com/c/net/+/691075
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2025-09-04 09:58:34 -07:00
Gopher Robot
c1e936d465 all: upgrade go directive to at least 1.24.0 [generated]
By now Go 1.25.0 has been released, and Go 1.23 is no longer supported
per the Go Release Policy (see https://go.dev/doc/devel/release#policy).

For golang/go#69095.

[git-generate]
(cd . && go get go@1.24.0 && go mod tidy && go fix ./... && go mod edit -toolchain=none)

Change-Id: I2363be0ee584129c16b07eb68a95f6f070477e07
Reviewed-on: https://go-review.googlesource.com/c/net/+/695279
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-13 08:18:57 -07:00
Gopher Robot
e74bc31d69 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Id3afb41fc96c3eaa63241116bb332d4779e6b5f6
Reviewed-on: https://go-review.googlesource.com/c/net/+/694175
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
v0.43.0
2025-08-07 12:56:06 -07:00
Alberto Donizetti
af6926ea18 http2: remove references to defunct http2.golang.org test server
The http2 demo server previously served at http2.golang.org has been
stopped (see golang/go#49301). This change removes a link to it from
the top-level package docs (which now just redirects to go.dev), and
switches the default hostname for the TransportExternal test to
go.dev.

It also delete an unused transport_test flag.

Updates golang/go#49301
Fixes golang/go#51540

Change-Id: I375250a8fec087124d42ed5f1086986e73e7bdfc
Reviewed-on: https://go-review.googlesource.com/c/net/+/693895
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2025-08-07 11:37:49 -07:00
Gopher Robot
76358aa57e go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Icb45ef272d4eb5920b8e531ba311b3efb42af72c
Reviewed-on: https://go-review.googlesource.com/c/net/+/687275
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
v0.42.0
2025-07-10 12:49:10 -07:00
Gopher Robot
6e41caea7e go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Ief62c666e731ea5aa7bbf9b6be66c47cb463f867
Reviewed-on: https://go-review.googlesource.com/c/net/+/679315
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
v0.41.0
2025-06-05 13:28:24 -07:00
Chressie Himpel
15f7d40345 http2: correctly wrap ErrFrameTooLarge in Framer.ReadFrame
In Framer.ReadFrame's frame-too-large check, the code that checks for
HTTP/1.1 looking frames accidentally wrapped the unrelated err from the
previous readFrameHeader call instead of ErrFrameTooLarge. Fix that.

Change-Id: I2237759eaad8c6e06e7195c50410abb5792e57ea
Reviewed-on: https://go-review.googlesource.com/c/net/+/676218
Reviewed-by: Chressie Himpel <chressie@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-27 23:45:28 -07:00
Damien Neil
ef33bc08f8 internal/http3: use bubbled context in synctest tests
Avoid using T.Context within a synctest bubble. If the Context's
Done channel is created outside the bubble, waiting on it within
the bubble is durably blocking. If it's created within the bubble,
the testing package encounters a panic when closing it after
CL 671960.

Instead, create our own Context within the bubble and cancel it
before the bubble is destroyed.

This will be entirely obviated by synctest.Test, which creates
a testing.T that returns a properly bubbled context.

Change-Id: Iff93c296ccbc1ece8172cb0a60e626ea1bd895ad
Reviewed-on: https://go-review.googlesource.com/c/net/+/675615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-05-22 15:58:59 -07:00
Evan Jones
919c6bc7ad http2: use an array instead of a map in typeFrameParser
FrameType is a dense integer range, so we can store the frameParsers
in an array instead of a map. This should be a very small performance
win on all Go http2 servers. For high QPS gRPC services, this function
is visible in the Go profiler. For example, it shows up as 0.16% of
all CPU time on one production service at Datadog.

Change FrameType.String() to use the same pattern.

Add a test for testFrameType with unknown FrameTypes.

Fixes golang/go#73613

Change-Id: I5f5b523e011a99d6b428cbdbfd97415e488169d1
Reviewed-on: https://go-review.googlesource.com/c/net/+/670415
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-12 12:37:34 -07:00
Egon Elbre
bae01a7353 trace: add missing td tag
Change-Id: I4f99953e028a6e397c62605f39b73872abf960bd
Reviewed-on: https://go-review.googlesource.com/c/net/+/670995
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-12 10:10:08 -07:00