aboutsummaryrefslogtreecommitdiff
path: root/src/net
AgeCommit message (Collapse)Author
2023-01-26net/http: keep sensitive headers on redirects to the same hostGustavo Falco
Preserve sensitive headers on a redirect to a different port of the same host. Fixes #35104 Change-Id: I5ab57c414ce92a70e688ee684b9ff02fb062b3c6 GitHub-Last-Rev: 8d53e71e2243c141d70d27a503d0f7e6dee64c3c GitHub-Pull-Request: golang/go#54539 Reviewed-on: https://go-review.googlesource.com/c/go/+/424935 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com>
2023-01-21net: add testing.Short Skip to test affected by local network configurationDavid Chase
If the local network mangles invalid DNS queries, that is not a Go problem. Change-Id: I54db392532eed988bca81b70a98cd6d11766af89 Reviewed-on: https://go-review.googlesource.com/c/go/+/461275 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-20net/http: close Request.Body when pconn write loop exits earlyDamien Neil
The pconn write loop closes a request's body after sending the request, but in the case where the write loop exits with an unsent request in writech the body is never closed. Close the request body in this case. Fixes #49621 Change-Id: Id94a92937bbfc0beb1396446f4dee32fd2059c7e Reviewed-on: https://go-review.googlesource.com/c/go/+/461675 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2023-01-19internal/godebug: export non-default-behavior counters in runtime/metricsRuss Cox
Allow GODEBUG users to report how many times a setting resulted in non-default behavior. Record non-default-behaviors for all existing GODEBUGs. Also rework tests to ensure that runtime is in sync with runtime/metrics.All, and generate docs mechanically from metrics.All. For #56986. Change-Id: Iefa1213e2a5c3f19ea16cd53298c487952ef05a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/453618 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-19runtime: replace panic(nil) with panic(new(runtime.PanicNilError))Russ Cox
Long ago we decided that panic(nil) was too unlikely to bother making a special case for purposes of recover. Unfortunately, it has turned out not to be a special case. There are many examples of code in the Go ecosystem where an author has written panic(nil) because they want to panic and don't care about the panic value. Using panic(nil) in this case has the unfortunate behavior of making recover behave as though the goroutine isn't panicking. As a result, code like: func f() { defer func() { if err := recover(); err != nil { log.Fatalf("panicked! %v", err) } }() call1() call2() } looks like it guarantees that call2 has been run any time f returns, but that turns out not to be strictly true. If call1 does panic(nil), then f returns "successfully", having recovered the panic, but without calling call2. Instead you have to write something like: func f() { done := false defer func() { if err := recover(); !done { log.Fatalf("panicked! %v", err) } }() call1() call2() done = true } which defeats nearly the whole point of recover. No one does this, with the result that almost all uses of recover are subtly broken. One specific broken use along these lines is in net/http, which recovers from panics in handlers and sends back an HTTP error. Users discovered in the early days of Go that panic(nil) was a convenient way to jump out of a handler up to the serving loop without sending back an HTTP error. This was a bug, not a feature. Go 1.8 added panic(http.ErrAbortHandler) as a better way to access the feature. Any lingering code that uses panic(nil) to abort an HTTP handler without a failure message should be changed to use http.ErrAbortHandler. Programs that need the old, unintended behavior from net/http or other packages can set GODEBUG=panicnil=1 to stop the run-time error. Uses of recover that want to detect panic(nil) in new programs can check for recover returning a value of type *runtime.PanicNilError. Because the new GODEBUG is used inside the runtime, we can't import internal/godebug, so there is some new machinery to cross-connect those in this CL, to allow a mutable GODEBUG setting. That won't be necessary if we add any other mutable GODEBUG settings in the future. The CL also corrects the handling of defaulted GODEBUG values in the runtime, for #56986. Fixes #25448. Change-Id: I2b39c7e83e4f7aa308777dabf2edae54773e03f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/461956 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
2023-01-19net: delete TestTCPSelfConnectBryan C. Mills
This test is flaky, apparently due to a typo'd operator in CL 21447 that causes it to compare “same port OR IP” instead of “same port AND IP”. If we merely fixed the comparison, the test would hopefully stop being flaky itself, but we would still be left with another problem: repeatedly dialing a port that we believe to be unused can interfere with other tests, which may open the previously-unused port and then attempt a single Dial and expect it to succeed. Arbitrary other Dial calls for that port may cause the wrong connection to be accepted, leading to spurious test failures. Moreover, the test can be extremely expensive for the amount of data we hope to get from it, depending on the system's port-reuse algorithms and dial implementations. It is already scaled back by up to 1000x on a huge number of platforms due to latency, and may even be ineffective on those platforms because of the arbitrary 1ms Dial timeout. And the incremental value from it is quite low, too: it tests the workaround for what is arguably a bug in the Linux kernel, which ought to be fixed (and tested) upstream instead of worked around in every open-source project that dials local ports. Instead of trying to deflake this test, let's just get rid of it. Fixes #18290. Change-Id: I8a58b93d67916a33741c9ab29ef99c49c46b32c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/460657 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-01-19net/netip: fix type name in TestNoAllocs sub-test names and commentsTobias Klauser
netaddr.IP became netip.Addr Change-Id: Ifa762d0f804c603e6289d63672e4808e75dc36a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/461748 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2023-01-06net: fix typo in hosts.goIkko Eltociear Ashimine
cannonical -> canonical Change-Id: I656ea210d8ef6eaa85245cb8f463f6b4fd67e1a2 GitHub-Last-Rev: 5a93045add2f2a6885b46377c784f665ab465cfd GitHub-Pull-Request: golang/go#57633 Reviewed-on: https://go-review.googlesource.com/c/go/+/460756 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2022-12-21net/http/httputil: don't add X-Forwarded-{Host,Proto} after invoking ↵Damien Neil
Director funcs This reverts CL 407414. When forwarding an inbound request that contains an existing X-Forwarded-Host or X-Forwarded-Proto header, a proxy might want to preserve the header from the inbound request, replace it with its own header, or not include any header at all. CL 407414 replaces inbound X-Forwarded-{Host,Proto} headers by default, and allows a Director func to disable sending these headers at all. However, the Director hook API isn't sufficiently flexible to permit the previous behavior of preserving inbound values unchanged. The new Rewrite API does have this flexibility; users of Rewrite can easily pick the exact behavior they want. Revert the change to ReverseProxy when using a Director func. Users who want a convenient way to set X-Forwarded-* headers to reasonable values can migrate to Rewrite at their convenience, and users depending on the current behavior will be unaffected. For #50465. Fixes #57132. Change-Id: Ic42449c1bb525d6c9920bf721efbc519697f4f20 Reviewed-on: https://go-review.googlesource.com/c/go/+/457595 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-12-21net: use correct dns msg sizeMateusz Poliwczak
Set bufSize to the actual dns message size, so that the p.Start (below) gets a fully valid dns message. Change-Id: I585e8a3d71f88db93e09bd0dbbc0875ee6de9a97 GitHub-Last-Rev: 0967be35012d2e28366e6d47eee4968c7e8d5e4a GitHub-Pull-Request: golang/go#57392 Reviewed-on: https://go-review.googlesource.com/c/go/+/458375 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-12-16os/user,net: add -fno-stack-protector to CFLAGSThan McIntosh
Some compilers default to having -fstack-protector on, which breaks when using internal linking because the linker doesn't know how to find the support functions. Updates #52919. Updates #54313. Fixes #57261. Change-Id: Iaae731851407af4521fff2dfefc5b7e3e92cf284 Reviewed-on: https://go-review.googlesource.com/c/go/+/456855 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-12-16net/http: improve errors in TestCancelRequestWhenSharingConnectionDamien Neil
Provide more information about why this test might be hanging waiting for PutIdleConn to be called (#56587): If the round trip that should result in PutIdleConn being invoked completes, report that to the goroutine waiting for PutIdleConn. For #56587 Change-Id: Ie476ea0ce4a48d2bda6b9b109f89d675a10e7e45 Reviewed-on: https://go-review.googlesource.com/c/go/+/457775 Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-12-07all: update vendored golang.org/x/netDamien Neil
Pull in HTTP/2 security fix: 1e63c2f08a http2: limit canonical header cache by bytes, not entries Fixes #56350 Change-Id: Ib14024ed894ba266f05d4a6e8c454234a45677d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/455717 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Jenny Rakoczy <jenny@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-06os, net/http: avoid escapes from os.DirFS and http.Dir on WindowsDamien Neil
Do not permit access to Windows reserved device names (NUL, COM1, etc.) via os.DirFS and http.Dir filesystems. Avoid escapes from os.DirFS(`\`) on Windows. DirFS would join the the root to the relative path with a path separator, making os.DirFS(`\`).Open(`/foo/bar`) open the path `\\foo\bar`, which is a UNC name. Not only does this not open the intended file, but permits reference to any file on the system rather than only files on the current drive. Make os.DirFS("") invalid, with all file access failing. Previously, a root of "" was interpreted as "/", which is surprising and probably unintentional. Fixes CVE-2022-41720 Fixes #56694 Change-Id: I275b5fa391e6ad7404309ea98ccc97405942e0f0 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1663834 Reviewed-by: Tatiana Bradley <tatianabradley@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/455362 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Jenny Rakoczy <jenny@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/455716 Reviewed-by: Jenny Rakoczy <jenny@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-12-05net: support context cancellation in resSearchMateusz Poliwczak
As with all the stuff that call cgo from net package. Change-Id: I7c42ae44a1d47f4f949b203682217498fcdba92a GitHub-Last-Rev: 70406493bbbe10bf556a17e453623d3decf00822 GitHub-Pull-Request: golang/go#57043 Reviewed-on: https://go-review.googlesource.com/c/go/+/454697 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-12-01net: acquire thread in resSearchMateusz Poliwczak
Change-Id: I042906d8eee8defafbd98f671fd30c2a68281705 GitHub-Last-Rev: 0660c9a989600eeb8652d1228777488d28397731 GitHub-Pull-Request: golang/go#57021 Reviewed-on: https://go-review.googlesource.com/c/go/+/454396 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-12-01net: retry with bigger buffer in resSearchMateusz Poliwczak
Glibc returns size > bufSize, when the entire dns reply does not fit inside the provided buffer. Change-Id: Ie1c1c6a3411880bd8bdb4371f1f1b7bcce837ea2 GitHub-Last-Rev: 488cd3ed0db2a86433aa921117b8f1e9192b1fa5 GitHub-Pull-Request: golang/go#57020 Reviewed-on: https://go-review.googlesource.com/c/go/+/454395 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-11-30net: reenable SRV tests with _ldap._tcp.google.comDamien Neil
TestLookupDotsWithRemoteSource and TestLookupGoogleSRV were disabled because they look up the no-longer-present SRV record for _xmpp-server._tcp.google.com. Change the tests to look for _ldap._tcp.google.com and reenable them. Fixes #56708. Change-Id: I26475fa3ff6fc008048a4e5f24f0e96ee12f655c Reviewed-on: https://go-review.googlesource.com/c/go/+/453861 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-30net/http: deflake and fix TestWrappedResponseControllerDamien Neil
Read the full (empty) response body before closing it, to avoid cancelling the request while the server handler is still running. Wrap the ResponseWriter before calling NewResponseController: This test is intended to verify that wrapping the controller works properly, but neglected to actually wrap the controller. Fixes #56961. Change-Id: I00269f897448ab34676338707b7a04d19ff17963 Reviewed-on: https://go-review.googlesource.com/c/go/+/453860 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-28net: gofmt after CL 382996Tobias Klauser
Change-Id: Ic1302eb02f4369bf6758be9fb91379fd9a992e48 Reviewed-on: https://go-review.googlesource.com/c/go/+/453575 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Damien Neil <dneil@google.com>
2022-11-22all: enable disabled HTTP/2 testsDamien Neil
Update net/http to enable tests that pass with the latest update to the vendored x/net. Update a few tests: Windows apparently doesn't guarantee that time.Since(time.Now()) is >=0, so to set a definitely-expired write deadline, use a time firmly in the past rather than now. Put a backoff loop on TestServerReadTimeout to avoid failures when the timeout expires mid-TLS-handshake. (The TLS handshake timeout is set to min(ReadTimeout, WriteTimeout, ReadHeaderTimeout); there's no way to set a long TLS handshake timeout and a short read timeout.) Don't close the http.Server in TestServerWriteTimeout while the handler may still be executing, since this can result in us getting the wrong error. Change the GOOS=js fake net implementation to properly return ErrDeadlineExceeded when a read/write deadline is exceeded, rather than EAGAIN. For #49837 For #54136 Change-Id: Id8a4ff6ac58336ff212dda3c8799b320cd6b9c19 Reviewed-on: https://go-review.googlesource.com/c/go/+/449935 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-22Revert "net/url, net/http/httputil: accept invalid percent encodings"Damien Neil
This reverts CL 450375. Reason for revert: This change causes test failures (and possibly other problems) for users depending on the existing validation behavior. Rolling back the change for now to give us more time to consider its impact. This landed late in the cycle and isn't urgent; it can wait for 1.21 if we do want to make the change. Fixes #56884 For #56732 Change-Id: I082023c67f1bbb933a617453ab92b67abba876ef Reviewed-on: https://go-review.googlesource.com/c/go/+/452795 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-11-22all: update vendored golang.org/x dependencies for Go 1.20 releaseCherry Mui
The Go 1.20 code freeze has recently started. This is a time to update all golang.org/x/... module versions that contribute packages to the std and cmd modules in the standard library to latest master versions. This CL updates them with x/build/cmd/updatestd. For #36905. Change-Id: Ie0ec91daeb848f00f64686003012297161ad02fa Reviewed-on: https://go-review.googlesource.com/c/go/+/452766 Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-11-19net/http: deflake TestIssue4191_InfiniteGetTimeoutDamien Neil
This test exercises the case where a net.Conn error occurs while writing a response body. It injects an error by setting a timeout on the Conn. If this timeout expires before response headers are written, the test fails. The test attempts to recover from this failure by extending the timeout and retrying. Set the timeout after the response headers are removed, and remove the retry loop. Fixes #56274. Change-Id: I293f8bedb7b20a21d14f43ea9bb48fc56b59441c Reviewed-on: https://go-review.googlesource.com/c/go/+/452175 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-19net/http: direct server logs to test output in testsDamien Neil
Set a logger in newClientServerTest that directs the server log output to the testing.T's log, so log output gets properly associated with the test that caused it. Change-Id: I13686ca35c3e21adae16b2fc37ce36daea3df9d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/452075 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-18net/http: regenerate h2_bundle.goDmitri Shuralyov
Done with: go generate -run=bundle std After CL 452096 updated the x/net version. Change-Id: I1c1cd76d4ec9e14f45dc66c945c74e41ff689a30 Reviewed-on: https://go-review.googlesource.com/c/go/+/452195 Reviewed-by: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-11-18net: fix typo in ControlContext parameter namesDamien Neil
Change-Id: I35fcfb2d8cafadca36cffeebe0858973895946d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/451419 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-18crypto/tls: add CertificateVerificationError to tls handshakeGabor Tanz
Fixes #48152 Change-Id: I503f088edeb5574fd5eb5905bff7c3c23b2bc8fc GitHub-Last-Rev: 2b0e982f3f6bca33062b0bbd64ed1804801e2c13 GitHub-Pull-Request: golang/go#56686 Reviewed-on: https://go-review.googlesource.com/c/go/+/449336 Run-TryBot: Roland Shoemaker <roland@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Julie Qiu <julieqiu@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-11-18all: add missing periods in commentscui fliter
Change-Id: I69065f8adf101fdb28682c55997f503013a50e29 Reviewed-on: https://go-review.googlesource.com/c/go/+/449757 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-17net: return errNoSuchHost when no entry found in /etc/hosts and order is ↵Mateusz Poliwczak
hostLookupFiles When /etc/nsswitch.conf lists: "hosts: files" then LookupHost returns two nils when no entry inside /etc/hosts is found. Change-Id: I96d68a079dfe009655c84cf0e697ce19a5bb6698 GitHub-Last-Rev: 894f066bbcc7c975f1975bd0d1dcb5726f590bc5 GitHub-Pull-Request: golang/go#56747 Reviewed-on: https://go-review.googlesource.com/c/go/+/450875 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-17net/http: deflake TestResponseControllerSetFutureWriteDeadlineDamien Neil
Don't set the server's write deadline until after the client has read the response headers, avoiding test failures if the deadline expires before or while writing headers. Fixes #56807. Change-Id: I5f80c108b360d030132a13661774a30fac453856 Reviewed-on: https://go-review.googlesource.com/c/go/+/451715 Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-17net: change resolverConfig.dnsConfig to an atomic.PointerIan Lance Taylor
We were using a RWMutex RLock around a single memory load, which is not a good use of a RWMutex--it introduces extra work for the RLock but contention around a single memory load is unlikely. And, the tryUpdate method was not acquiring the mutex anyhow. The new atomic.Pointer type is type-safe and easy to use correctly for a simple use-case like this. Change-Id: Ib3859c03414c44d2e897f6d15c92c8e4b5c81a11 Reviewed-on: https://go-review.googlesource.com/c/go/+/451416 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-11-16net: remove unused goLookupHost methodMateusz Poliwczak
Change-Id: I62b9d0dcbec647fdd3279d78b9999dd933ff0bbd GitHub-Last-Rev: f83db66c935dd7a14128d1e87c9323539e9d2d16 GitHub-Pull-Request: golang/go#56758 Reviewed-on: https://go-review.googlesource.com/c/go/+/451135 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-15net: rewrite nsswitch.conf parsing to work like other parsersIan Lance Taylor
Seems simpler than having two different parsing mechanisms. Change-Id: I4f8468bc025f8e03f59ec9c79b17721581b64eed Reviewed-on: https://go-review.googlesource.com/c/go/+/448855 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-11-15net: use a consistent dnsConfig in hostLookupOrderMateusz Poliwczak
Use the same dnsConfig throughout a DNS lookup operation. Before this CL it was possible to decide to re-read a modified resolv.conf file during the DNS lookup, which could lead to inconsistencies between the lookup order and the name server list. Change-Id: I0689749272b8263268d00b9a9cb4458cd68b23eb GitHub-Last-Rev: 64810a22bc8a7dd5e804b5f5253d11b73942dfe3 GitHub-Pull-Request: golang/go#56690 Reviewed-on: https://go-review.googlesource.com/c/go/+/449337 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> 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-11-15net/url, net/http/httputil: accept invalid percent encodingsIan Lance Taylor
Per https://url.spec.whatwg.org/#percent-encoded-bytes an invalid percent encoding should be handled as ordinary text. Fixes #56732 Change-Id: Ib0259dfd704922905289eebaacbf722e28f6d636 Reviewed-on: https://go-review.googlesource.com/c/go/+/450375 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-14internal/godebug: define more efficient APIRuss Cox
We have been expanding our use of GODEBUG for compatibility, and the current implementation forces a tradeoff between freshness and efficiency. It parses the environment variable in full each time it is called, which is expensive. But if clients cache the result, they won't respond to run-time GODEBUG changes, as happened with x509sha1 (#56436). This CL changes the GODEBUG API to provide efficient, up-to-date results. Instead of a single Get function, New returns a *godebug.Setting that itself has a Get method. Clients can save the result of New, which is no more expensive than errors.New, in a global variable, and then call that variable's Get method to get the value. Get costs only two atomic loads in the case where the variable hasn't changed since the last call. Unfortunately, these changes do require importing sync from godebug, which will mean that sync itself will never be able to use a GODEBUG setting. That doesn't seem like such a hardship. If it was really necessary, the runtime could pass a setting to package sync itself at startup, with the caveat that that setting, like the ones used by runtime itself, would not respond to run-time GODEBUG changes. Change-Id: I99a3acfa24fb2a692610af26a5d14bbc62c966ac Reviewed-on: https://go-review.googlesource.com/c/go/+/449504 Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-11net: handle correctly the _gateway and _outbound hostnames for nss myhostnameMateusz Poliwczak
Fixes #56387 Change-Id: If412134344600caefec425699398522399986d4d GitHub-Last-Rev: f33540ef8f90e9a8c09f3947aba8c01155516d39 GitHub-Pull-Request: golang/go#56388 Reviewed-on: https://go-review.googlesource.com/c/go/+/445075 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-11net: disable TestLookupDotsWithRemoteSource and TestLookupGoogleSRVMichael Anthony Knyszek
These tests fail consistently due to a DNS change causing widespread trybot outages. Fixes #56707. Change-Id: Iebdf91254a922a48880021198f0f12f6bc16b6e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/449640 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2022-11-11net/http: fix triv.goRuss Cox
CL 428137 replaced 'buf := make(bytes.Buffer)' with 'var buf strings.Builder'. That change also requires passing &buf to io.Copy instead of buf. Change-Id: I72b3faa46693e7d1441298f49dc6b95859c3bff3 Reviewed-on: https://go-review.googlesource.com/c/go/+/449635 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Russ Cox <rsc@golang.org>
2022-11-10net: auto-reload the /etc/nsswitch.conf on unix systemsMateusz Poliwczak
This change is made to align with the current (recently changed) glibc behaviour, it will allow the hostLookupOrder method to change its decisions on runtime (based on /etc/nsswitch.conf changes). Fixes #56515 Change-Id: I241d67f053b6d2111eebcd67744adee02829166e GitHub-Last-Rev: 82842c127474d5d225d2e9b68568387ee6b0ba04 GitHub-Pull-Request: golang/go#56588 Reviewed-on: https://go-review.googlesource.com/c/go/+/448075 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-11-10net: unify TCP keepalive behaviordatabase64128
CL 107196 introduced a default TCP keepalive interval for Dialer and TCPListener (used by both ListenConfig and ListenTCP). Leaving DialTCP out was likely an oversight. DialTCP's documentation says it "acts like Dial". Therefore it's natural to also expect DialTCP to enable TCP keepalive by default. This commit addresses this disparity by moving the enablement logic down to the newTCPConn function, which is used by both dialer and listener. Fixes #49345 Change-Id: I99c08b161c468ed0b993d1dbd2bd0d7e803f3826 GitHub-Last-Rev: 5c2f1cb0fbc5e83aa6cdbdf3ed4e23419d9bca65 GitHub-Pull-Request: golang/go#56565 Reviewed-on: https://go-review.googlesource.com/c/go/+/447917 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-10net/http: build error chains in transport that can be unwrappedMarcus Weiner
In some places of the HTTP transport errors were constructed that wrapped other errors without providing the ability to call `errors.Unwrap` on them to get the underlying error. These places have been fixed to use `%w` when using `fmt.Errorf` or to implement `Unwrap() error`. Fixes #56435 Change-Id: Ieed3359281574485c8d0b18298e25e5f1e14555c GitHub-Last-Rev: 504efbc507a50bd2cf63001511733e232927089f GitHub-Pull-Request: golang/go#56451 Reviewed-on: https://go-review.googlesource.com/c/go/+/445775 Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-10net: add support for /etc/hosts aliases using go resolverMateusz Poliwczak
It adds support for /etc/hosts aliases and fixes the difference between the glibc cgo and the go DNS resolver. Examples: https://pastebin.com/Fv6UcAVr Fixes #44741 Change-Id: I98c484fced900731fbad800278b296028a45f044 GitHub-Last-Rev: 3d47e44f11c350df906d0c986e41891dd6e8d929 GitHub-Pull-Request: golang/go#51004 Reviewed-on: https://go-review.googlesource.com/c/go/+/382996 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-10net/http: add ResponseController and per-handler timeoutsDamien Neil
The ResponseController type provides a discoverable interface to optional methods implemented by ResponseWriters. c := http.NewResponseController(w) c.Flush() vs. if f, ok := w.(http.Flusher); ok { f.Flush() } Add the ability to control per-request read and write deadlines via the ResponseController SetReadDeadline and SetWriteDeadline methods. For #54136 Change-Id: I3f97de60d4c9ff150cda559ef86c6620eee665d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/436890 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-10net/http: add tests for Server.ReadTimeout and server.WriteTimeoutDamien Neil
We don't seem to have tests verifying that handler reads from the request body or writes to the response body time out properly. Add some. For #49837 For #56478 Change-Id: I0828edd6c86b071073fd1b22ccbb24f86114ab94 Reviewed-on: https://go-review.googlesource.com/c/go/+/446255 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-09net/http: add Transport.OnProxyConnectResponsecuiweixie
Fixes #54299 Change-Id: I3a29527bde7ac71f3824e771982db4257234e9ef Reviewed-on: https://go-review.googlesource.com/c/go/+/447216 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: xie cui <523516579@qq.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2022-11-09all: fix some commentscui fliter
Change-Id: I163ea3a770f2228f67d4fb1374653566e64b91f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/448575 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-09io: correctly process result of sendfile(2) when src returns 0 bytesDaulet Zhanguzin
Fixes #53658. io.Copy() uses sendfile(2) to avoid allocating extra buffers when src is a file and dst is a TCPConn. However if src returns no bytes current logic treats it as failure and falls back to copying via user space. The following is a benchmark that illustrates the bug. Benchmark: https://go.dev/play/p/zgZwpjUatSq Before: BenchmarkCopy-16 541006 2137 ns/op 4077 B/op 0 allocs/op After: BenchmarkCopy-16 490383 2365 ns/op 174 B/op 8 allocs/op Change-Id: I703376d53b20e080c6204a73c96867cce16b24cf GitHub-Last-Rev: 3a50be4f169683bf9caea32892c66619a66ad21a GitHub-Pull-Request: golang/go#53659 Reviewed-on: https://go-review.googlesource.com/c/go/+/415834 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-08net: allocate res_state entirely in C memoryRuss Cox
The linux-amd64-wsl builder was failing because the res_nsearch implementation was storing pointer to the res_state's own fields in other fields in the res_state. If the res_state is Go memory, this looks like pointers to Go pointers. Moving the res_state to C memory avoids the problem. The linux-amd64-wsl builder has been fixed a different way by replacing res_nsearch with res_search on Linux, where it is thread-safe. But other systems that still need to use res_nsearch (such as macOS) may run into the same kind of problem, so it is probably still worth arranging for the res_state to live entirely in C memory. Fixes #56658 (again). Change-Id: I58a14e72c866eaceb02ad828854a1f626b9b8e73 Reviewed-on: https://go-review.googlesource.com/c/go/+/448798 Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>