Commit Graph

2263 Commits

Author SHA1 Message Date
Dmitri Shuralyov
7c360367ab http2, webdav, websocket: fix %q verb uses with wrong type
Caught early by the improved vet check gated behind the 1.26 language
version combined with a tiplang builder that tests with 1.26 language
version.

Fixes golang/go#76574.
Fixes golang/go#76599.
Fixes golang/go#76547.

Change-Id: If8e2266013df0a39fc980a1e9287f8cb75949811
Cq-Include-Trybots: luci.golang.try:x_net-gotip-linux-amd64-tiplang
Reviewed-on: https://go-review.googlesource.com/c/net/+/725220
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2025-11-28 14:06:04 -08:00
Marcus Efraimsson
ec11eccf5a trace: fix data race in RenderEvents
This commit updates the RenderEvents function by moving the read
lock for event families so that it happens before checking the
length of event families and by that fixing a data race problem.

Fixes golang/go#76402

Change-Id: Id02ebaa25cec8ef631aaf928ba084b0692e84583
Reviewed-on: https://go-review.googlesource.com/c/net/+/723160
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-11-24 17:04:07 -08:00
Damien Neil
bff14c5256 http2: don't PING a responsive server when resetting a stream
When sending a RST_STREAM for a canceled request, we sometimes send
a PING frame along with the reset to confirm that the server is responsive
and has received the reset.

Sending too many PINGs trips denial-of-service detection on some servers,
causing them to close a connection with an ENHANCE_YOUR_CALM error.

Do not send a PING frame along with an RST_STREAM if the connection
has displayed signs of life since the canceled request began.
Specifically, if we've received any stream-related frames since the
request was sent, assume the server is responsive and do not send a PING.

We still send a PING if a request is canceled and no stream-related
frames have been received from the server since the request was first
sent.

For golang/go#76296

Change-Id: I1be3532febf9ac99d65e9cd35346c02306db5f9d
Reviewed-on: https://go-review.googlesource.com/c/net/+/720300
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-11-24 14:35:53 -08:00
Damien Neil
88a642172c dns/dnsmessage: avoid use of "strings" and "math" in dns/dnsmessage
dns/dnsmessage is used by the net package, which does not have
strings and math in its permitted dependencies.

Change-Id: I2b59887c59891dc61e49dd6430f3a72486ddd66a
Reviewed-on: https://go-review.googlesource.com/c/net/+/723902
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>
2025-11-24 14:33:11 -08:00
Damien Neil
123d099e1b http2: support net/http.Transport.NewClientConn
Permit net/http to create new HTTP/2 client connections.

We do this by adding a NewClientConn method to the type the HTTP/2 client
registers with net/http.Transport.RegisterProtocol, which creates a
persistent connection from a net.Conn.

No tests in this CL. Tests will be in net/http, and will cover
both the HTTP/1 and HTTP/2 paths for NewClientConn.

For golang/go#75772

Change-Id: Ib1a06b4d13fdd6008e5db9a090c6e9632029a2a4
Reviewed-on: https://go-review.googlesource.com/c/net/+/722200
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-11-24 11:30:53 -08:00
Damien Neil
346cc6157e webdav: relax test to check for any redirect status, not just 301
CL 720820 changed net/http to use a 307 Temporary Redirect instead of
a 301 Moved Permanently when performing an automatic redirect under
some circumstances. Update tests in the webdav package to be agnostic
on the exact redirect status code.

Change-Id: I71784a738d18928a98387ddbd5475d50b19d15bf
Reviewed-on: https://go-review.googlesource.com/c/net/+/723120
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Auto-Submit: Nicholas Husin <nsh@golang.org>
2025-11-21 16:46:41 -08:00
Gopher Robot
9a296438e5 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: I166e970128861674939fc46eaad37f74d19f1745
Reviewed-on: https://go-review.googlesource.com/c/net/+/719680
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>
Auto-Submit: Gopher Robot <gobot@golang.org>
v0.47.0
2025-11-11 10:55:31 -08:00
Damien Neil
07cefd8a6b context: deprecate
Long superseded by the stdlib's context package.

Fixes golang/go#49506

Change-Id: I16e9a1275a7370cd78d11180f608ae28ecdce143
Reviewed-on: https://go-review.googlesource.com/c/net/+/719060
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2025-11-08 12:28:41 -08:00
Sean Liao
5ac9daca08 publicsuffix: don't treat ip addresses as domain names
While IP addresses are not domain names and probably
shouldn't be passed to these functions at all, it seems
wrong to have it handle IPv4 and IPv6 differently.

Fixes golang/go#32979

Change-Id: Id321a08b552c11d990c3966636b64793f762143f
Reviewed-on: https://go-review.googlesource.com/c/net/+/715100
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-11-04 13:39:14 -08:00
Damien Neil
d1f64cc670 quic: use testing/synctest
Replace bespoke fake time and synchronization with testing/synctest.

Change-Id: Ic3fe9635dbad36c890783c38e00708c6cb7a15f8
Reviewed-on: https://go-review.googlesource.com/c/net/+/714482
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: Damien Neil <dneil@google.com>
2025-10-27 13:48:05 -07:00
Nicholas S. Husin
fff0469cf5 http2: document that RFC 7540 prioritization does not work with small payloads
This change demonstrates that golang/go#75936 applies to the RFC 7540
write scheduler.

A similar test will be added for RFC 9218 write scheduler after support
for it is incorporated within http2/server.go.

For golang/go#75936

Change-Id: I4e05dbeb0aab71942eb699b67383ef5b52c3ef4d
Reviewed-on: https://go-review.googlesource.com/c/net/+/714741
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-24 15:04:41 -07:00
Nicholas S. Husin
f35e3a4dd2 http2: fix weight overflow in RFC 7540 write scheduler
We use uint8 (0-255, inclusive) to represent the RFC 7540 priorities
weight (1-256, inclusive). To account for the difference, we add 1 to
the uint8 weight value within sortPriorityNodeSiblingsRFC7540.

However, the addition was done before converting the uint8 type to
float. As a result, when provided a maximum weight value, overflow will
happen and will cause the scheduler to treat the maximum weight as a
minimum weight instead.

This CL fixes the issue by making sure the addition happens after the
type conversion.

Change-Id: I404e87e5ad85fa06d5fa49cda613c93ac8847bdc
Reviewed-on: https://go-review.googlesource.com/c/net/+/714742
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-24 15:04:30 -07:00
Nicholas S. Husin
89adc90ac4 http2: fix typo referring to RFC 9218 as RFC 9128 instead
In go.dev/cl/704758, I accidentally typed RFC 9128 rather than 9218.
This changes fixes all such typo.

For go/golang#75500

Change-Id: I61c3008a85ca0ca0e9f58315cb5eb20cd82fb9f9
Reviewed-on: https://go-review.googlesource.com/c/net/+/714740
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-24 15:04:23 -07:00
Damien Neil
8d76a2c082 quic: don't defer MAX_STREAMS frames indefinitely
Avoid a state where we can have a MAX_STREAMS frame to send,
but do not send the frame for an indefinite amount of time.

Conn.appendStreamFrames writes stream-related frames to
the current packet. It also handles removing streams
from the Conn when we no longer need to track their state.

Removing streams can affect the frames we want to send.
In particular, we may want to send a MAX_STREAMS to the
peer indicating that it can open more streams because
we've closed out some of the existing ones.

Add MAX_STREAMS after removing streams, to ensure we
pick up any changes to the sent value before adding it.

This case doesn't show up in  tests, because the test harness's
idleness detection causes the Conn's event loop to run and notice
the pending MAX_STREAMS frame. Changing tests to use
testing/synctest (a followup CL) causes the problem to
appear, because the event loop isn't run while the Conn
is idle.

Change-Id: Ia7394891317dae6ecfd529a9b3501ac082cb453e
Reviewed-on: https://go-review.googlesource.com/c/net/+/714481
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-10-24 07:51:19 -07:00
Damien Neil
027f8b700e quic: fix expected ACK Delay in client's ACK after HANDSHAKE_DONE
testConn.handshake runs through the initial QUIC handshake
and verifies that the connection under test sends an expected
sequence of handshake messages.

The last datagram in the handshake is sent by the client,
and contains an ACK for the last datagram sent by the server.

The client sends this ACK after max_ack_delay (25ms) passes, minus
the timer granularity (1ms). The timer granularity is a constant
containing the expected maximum delay between a timer event's
scheduled time and the timer actually firing.

The expected handshake datagram used by testConn.handshake contains
an ACK with an ACK Delay value of 25ms (max_ack_delay).
This doesn't account for the timer granularity adjustment.
However, since testConn.handshake advances time by 25ms rather than 24ms,
the test connection sends the ACK at the later time and includes a
larger ACK Delay value.

Fix testConn.handshake to sleep for the expected delay (24ms).
Fix the expected handshake datagram accordingly.

This all avoids test failures after switching this package to use
testing/synctest's fake clock, under which the connection sends
this ACK at the scheduled time rather than a time under direct
control of the test.

Change-Id: I1af6e02e02f6493758e41db45a46d06a65441a7b
Reviewed-on: https://go-review.googlesource.com/c/net/+/714480
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
2025-10-24 07:51:16 -07:00
Vinicius Fortuna
dec9fe711e dns/dnsmessage: update SVCB packing to prohibit name compression
This commit updates the dns/dnsmessage package to correctly handle SVCB record
packing by prohibiting name compression for the Target field.

It turns out the compression of names in RDATA is prohibited (see
https://datatracker.ietf.org/doc/html/rfc3597#section-4), except for well-known record
types (those defined in https://datatracker.ietf.org/doc/html/rfc1035).

The SVCB RFC actually explicitly calls that out
(https://datatracker.ietf.org/doc/html/rfc9460#section-2.2), so it was an oversight
in my part in https://go.dev/cl/710736.

Updates golang/go#43790

Change-Id: I287b034c9e01b49264e07e23293bacd830ab1832
GitHub-Last-Rev: 1d16664c57
GitHub-Pull-Request: golang/net#242
Reviewed-on: https://go-review.googlesource.com/c/net/+/713900
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Vinicius Fortuna <fortuna@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
2025-10-23 13:39:34 -07:00
cuishuang
9be1ff2808 all: fix some comments
Change-Id: I4a06e68307ac3deb5b2e1bab9235ebe01dcd4ea6
Reviewed-on: https://go-review.googlesource.com/c/net/+/713380
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
2025-10-23 07:34:54 -07:00
Rhys Hiltner
6e243da531 quic: update Initial keys when handling Retry
A Retry packet specifies a new connection ID for the client to use as a
destination address, in what the server will consider to be the client's
"first" Initial packet. Re-derive the Initial space's packet protection
keys, since that address is an input to their derivation function.

"Changing the Destination Connection ID field also results in a change
to the keys used to protect the Initial packet."
https://www.rfc-editor.org/rfc/rfc9000#section-17.2.5.2-4

For golang/go#58547

Change-Id: Id8acf5788a05d367f952dce33ef4b06f7e8b66e2
Reviewed-on: https://go-review.googlesource.com/c/net/+/712341
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-17 13:07:34 -07:00
Rhys Hiltner
98daa2e33a quic: send ECN feedback to peers
Track the total number of ECT(0), ECT(1), and ECN-CE state of packets we
process in each packet number space. Send it back to the peer in each
ACK frame (unless it's all zeros).

"Even if an endpoint does not set an ECT field in packets it sends, the
endpoint MUST provide feedback about ECN markings it receives, if these
are accessible."
https://www.rfc-editor.org/rfc/rfc9000#section-13.4.1-2

For golang/go#58547

Change-Id: I3ce5be6c536198eaa711f527402503b0567fc7a5
Reviewed-on: https://go-review.googlesource.com/c/net/+/712280
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-17 13:04:03 -07:00
Alexander Yastrebov
c296fafc21 net/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

Change-Id: I0fdc0c0a5947d27dcc615e5bcf4d4620c2c95d9e
GitHub-Last-Rev: 4d04dc93f3
GitHub-Pull-Request: golang/net#239
Reviewed-on: https://go-review.googlesource.com/c/net/+/710235
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-10-15 17:07:03 -07:00
Mateusz Poliwczak
ef82ae896f dns/dnsmessage: return an error for too long SVCParam.Value
Updates #43790

Change-Id: Id9f5bdc3e17a6f7d2c9b7b8a4e48c0c66a6a6964
Reviewed-on: https://go-review.googlesource.com/c/net/+/712080
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Vinicius Fortuna <fortuna@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-15 14:03:36 -07:00
Rhys Hiltner
3ba82d21c9 internal/quic/cmd/interop: test ChaCha20 on server
The QUIC interop test suite confirms support for ChaCha20. Go's TLS
implementation doesn't allow configuring ciphersuites for TLS 1.3, so we
cannot force the client hello to offer only ChaCha20 as the test
requires.

When acting as a server, we still cannot control which ciphersuites we
offer, but we can make the binary choice of whether we respond to the
client hello (which includes its offer of ciphersuites).

Use that to implement the server side of the ChaCha20 interop test. This
tells a more complete story of our level of ChaCha20 support: it works
when negotiated.

Fixes golang/go#75912

Change-Id: I1d8d08e4f4b8eb89bf11e9e4ae1aaa5c0709a530
Reviewed-on: https://go-review.googlesource.com/c/net/+/712120
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-15 13:27:37 -07:00
Vinicius Fortuna
bb2055dafd dns/dnsmessage: add https svcb dns types
This change implements the proposal to add new DNS message types HTTPS and
SVCB in the golang.org/x/net/dns/dnsmessage package, as described in
golang/go#43790.

The implementation includes:
- New types TypeHTTPS and TypeSVCB.
- SVCBResource and HTTPSResource structs, with HTTPSResource embedding
  SVCBResource.
- SVCParam and SVCParamKey types for handling service parameters.
- pack and unpack methods for the new resource types.
- Integration into the Parser and Builder.
- Comprehensive tests, including for parameter handling logic.

I implemented the SVCB parsing code so that it performs only two
allocations: one for the []SVCParam slice, and one to hold the SVCParam
values. A test was added to demonstrate that.

Fixes golang/go#43790

Change-Id: I60439772fe0e339ae3141bd1dd9829564efe0f2a
GitHub-Last-Rev: 49c2ac0102
GitHub-Pull-Request: golang/net#241
Reviewed-on: https://go-review.googlesource.com/c/net/+/710736
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Vinicius Fortuna <fortuna@google.com>
2025-10-15 07:15:29 -07:00
Arjan Bal
63d1a5100f http2: Allow reading frame header and body separately
This change exports two new methods on the Framer, ReadFrameHeader and
ReadFrameBodyForHeader, which split the functionality of the existing
ReadFrame method.

This provides more granular control, allowing callers to inspect the
frame header before deciding whether or how to read the frame body.
This is useful for applications that may need to make decisions based on frame
type.

Fixes golang/go#73560

Change-Id: I60b42d2889095fac8e243022886740bc6dd94012
Reviewed-on: https://go-review.googlesource.com/c/net/+/710515
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-10-13 16:47:38 -07: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