aboutsummaryrefslogtreecommitdiff
path: root/src/net
AgeCommit message (Collapse)Author
2023-10-14all: fix function namescui fliter
Change-Id: Iba8878420c59d705066d1d9955e91a5c2eb4faf5 Reviewed-on: https://go-review.googlesource.com/c/go/+/507615 Reviewed-by: Ian Lance Taylor <iant@golang.org> 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: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-10-11net: clear malloc'ed memory in cgoResSearchIan Lance Taylor
For #61666 Change-Id: I7a0a849fba0abebe28804bdd6d364b154456e399 Reviewed-on: https://go-review.googlesource.com/c/go/+/534516 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-10-10all: pull in x/net v0.17.0 and its dependenciesDmitri Shuralyov
Pull in a security fix from x/net/http2: http2: limit maximum handler goroutines to MaxConcurrentStreams Fixes #63417. Fixes CVE-2023-39325. Change-Id: I01e7774912e81007a7cf70f33e5989fb50a0b708 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/534295 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-05net/http: fix ServeMux pattern registrationJonathan Amsterdam
When the httpmuxgo121 GODEBUG setting was active, we were registering patterns in the old and the new way. Fix to register only in the old way. Change-Id: Ibc1fd41e7f4d162ee5bc34575df409e1db5657cd Reviewed-on: https://go-review.googlesource.com/c/go/+/533095 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Olena Synenka <olenasynenka@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-10-04net/http/cgi: set SERVER_PORT to 443 when req.TLS != niledef
A hostname without a port leaves the port implied by the protocol. For HTTPS, the implied port is 443, not 80. Change-Id: I873a076068f84c8041abf10a435d9499635730a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/454975 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-03net/http: document new ServeMux patternsJonathan Amsterdam
Updates #61410. Change-Id: Ib9dd8ebca43cec6e27c6fdfcf01ee6a1539c2fa0 Reviewed-on: https://go-review.googlesource.com/c/go/+/530481 Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-10-02net: handle the network parameter properly in LookupPortMateusz Poliwczak
The cgo version (unix) is populating the GetAddrInfo hints based on the network parameter, but windows not quite. This change populates the hints the same way as the cgo unix version does now. This bug was spotted by Bryan in CL 530415. https://go-review.googlesource.com/c/go/+/530415/comment/76640dc7_ed0409ca/ Change-Id: I6fc29b1e4cdc879123ab0f5a624b6f37c68c00ba GitHub-Last-Rev: eaa616378b3fa9a5a72192f3d501c591804f45d8 GitHub-Pull-Request: golang/go#63284 Reviewed-on: https://go-review.googlesource.com/c/go/+/531635 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David du Colombier <0intro@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-10-02net/http: add a test for an empty ServeMuxJonathan Amsterdam
Make sure a ServeMux with no patterns is well-behaved. Updates #61410. Change-Id: Ib3eb85b384e1309e785663902d2c45ae01e64807 Reviewed-on: https://go-review.googlesource.com/c/go/+/530479 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-10-02net/http: add GODEBUG setting for old ServeMux behaviorJonathan Amsterdam
Add the GODEBUG setting httpmuxgo121. When set to "1", ServeMux behaves exactly like it did in Go 1.21. Implemented by defining a new, unexported type, serveMux121, that uses the original code. Updates #61410. Change-Id: I0a9d0fe2a2286e442d680393e62895ab50683cea Reviewed-on: https://go-review.googlesource.com/c/go/+/530461 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-28net: set IsNotFound for unknown services in LookupPortMateusz Poliwczak
Change-Id: I9d5f0ea5edd2c121179e3d2f8d4a890fa25a3fa9 GitHub-Last-Rev: 48a13fe5f51b8208784bd38de3fc14f0997c8ff7 GitHub-Pull-Request: golang/go#63160 Reviewed-on: https://go-review.googlesource.com/c/go/+/530415 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-27net/http: add extra synchronization for a Logf call in ↵Bryan C. Mills
TestTransportAndServerSharedBodyRace This race was reported in https://build.golang.org/log/6f043170946b665edb85b50804a62db68348c52f. As best as I can tell, it is another instance of #38370. The deferred call to backend.close() ought to be enough to ensure that the t.Logf happens before the end of the test, but in practice it is not, and with enough scheduling delay we can manage to trip the race detector on a call to Logf after the test function has returned. Updates #38370. Change-Id: I5ee45df45c6bfad3239d665df65a138f1c4573a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/531195 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-25net/http: remove unused functionJonathan Amsterdam
Change-Id: I4364d94663282249e632d12026a810147844ad2e Reviewed-on: https://go-review.googlesource.com/c/go/+/530615 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-25net/http: unescape paths and patterns by segmentJonathan Amsterdam
When parsing patterns and matching, split the path into segments at slashes, then unescape each segment. This behaves as most people would expect: - The pattern "/%61" matches the paths "/a" and "/%61". - The pattern "/%7B" matches the path "/{". (If we did not unescape patterns, there would be no way to write that pattern: because "/{" is a parse error because it is an invalid wildcard.) - The pattern "/user/{u}" matches "/user/john%2Fdoe" with u set to "john/doe". - The unexpected redirections of #21955 will not occur. A later CL will restore the old behavior behind a GODEBUG setting. Updates #61410. Fixes #21955. Change-Id: I99025e149021fc94bf87d351699270460db532d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/530575 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-20all: simplify bool conditionsOleksandr Redko
Change-Id: Id2079f7012392dea8dfe2386bb9fb1ea3f487a4a Reviewed-on: https://go-review.googlesource.com/c/go/+/526015 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com>
2023-09-20net/http: eliminate more clientServerTest leaks in tests that use ↵Bryan C. Mills
runTimeSensitiveTest Change-Id: I77684a095af03d5c4e50da8e7af210b10639ff23 Reviewed-on: https://go-review.googlesource.com/c/go/+/529756 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-20net/http: eliminate a goroutine leak in (*persistConn.addTLS)Bryan C. Mills
In case of a handshake timeout, the goroutine running addTLS closes the underlying connection, which should unblock the call to tlsConn.HandshakeContext. However, it didn't then wait for HandshakeContext to actually return. I thought this might have something to do with #57602, but as far as I can tell it does not. Still, it seems best to avoid the leak: if tracing is enabled we emit a TLSHandshakeDone event, and it seems misleading to produce that event when the handshake is still in progress. For #57602. Change-Id: Ibfc0cf4ef8df2ccf11d8897f23d7d79ee482d5fb Reviewed-on: https://go-review.googlesource.com/c/go/+/529755 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Commit-Queue: Bryan Mills <bcmills@google.com>
2023-09-19net/http: add a benchmark for multi indexingJonathan Amsterdam
We don't index multis, so a corpus full of them will take quadratic time to check for conflicts. How slow is that going to be in practice? This benchmark indexes and checks a thousand multi patterns, all disjoint. It runs in about 35ms. Change-Id: Id27940ab19ad003627bd5c43c53466e01456b796 Reviewed-on: https://go-review.googlesource.com/c/go/+/529477 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-19net/http: test index exhaustivelyJonathan Amsterdam
Replace the fuzz test with one that enumerates all relevant patterns up to a certain length. For conflict detection, we don't need to check every possible method, host and segment, only a few that cover all the possibilities. There are only 2400 distinct patterns in the corpus we generate, and the test generates, indexes and compares them all in about a quarter of a second. Change-Id: I9fde88e87cec07b1b244306119e4e71f7205bb77 Reviewed-on: https://go-review.googlesource.com/c/go/+/529556 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-19net/http: show offset in pattern parsing errorJonathan Amsterdam
Track the offset in the pattern string being parsed so we can show it in the error message. Change-Id: I495b99378d866f359f45974ffc33587e2c1e366d Reviewed-on: https://go-review.googlesource.com/c/go/+/529123 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-19net/http: explain why two patterns conflictJonathan Amsterdam
It can be difficult to tell at a glance why two patterns conflict, so explain it with example paths. Change-Id: Ie384f0a4ef64f30e6e6898bce4b88027bc81034b Reviewed-on: https://go-review.googlesource.com/c/go/+/529122 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-19net/http: index patterns for faster conflict detectionJonathan Amsterdam
Add an index so that pattern registration isn't always quadratic. If there were no index, then every pattern that was registered would have to be compared to every existing pattern for conflicts. This would make registration quadratic in the number of patterns, in every case. The index in this CL should help most of the time. If a pattern has a literal segment, it will weed out all other patterns that have a different literal in that position. The worst case will still be quadratic, but it is unlikely that a set of such patterns would arise naturally. One novel (to me) aspect of the CL is the use of fuzz testing on data that is neither a string nor a byte slice. The test uses fuzzing to generate a byte slice, then decodes the byte slice into a valid pattern (most of the time). This test actually caught a bug: see https://go.dev/cl/529119. Change-Id: Ice0be6547decb5ce75a8062e4e17227815d5d0b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/529121 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-19net/http: buffer the testConn close channel in ↵Bryan C. Mills
TestHandlerFinishSkipBigContentLengthRead Previously the test used an unbuffered channel, but testConn.Close sends to it with a select-with-default, so the send would be dropped if the test goroutine happened not to have parked on the receive yet. To make this kind of bug less likely in future tests, use a newTestConn helper function instead of constructing testConn channel literals in each test individually. Fixes #62622. Change-Id: I016cd0a89cf8a2a748ed57a4cdbd01a178f04dab Reviewed-on: https://go-review.googlesource.com/c/go/+/529475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-18net/http: fix bugs in comparePaths and combineRelationshipsJonathan Amsterdam
combineRelationships was wrong on one case: if one part of a pattern overlaps and the other is disjoint, the result is disjoint, not overlaps. For example: /a/{x}/c /{x}/b/d Here the prefix consisting of the first two segments overlaps, but the third segments are disjoint. The patterns as a whole are disjoint. comparePaths was wrong in a couple of ways: First, the loop shouldn't exit early when it sees an overlap, for the reason above: later information may change that. Once the loop was allowed to continue, we had to handle the "overlaps" case at the end. The insight there, which generalized the existing code, is that if the shorter path ends in a multi, that multi matches the remainder of the longer path and more. (It must be "and more": the longer path has at least two segments, so it couldn't match one segment while the shorter path's multi can.) That means we can treat the result as the combination moreGeneral and the relationship of the common prefix. Change-Id: I11dab2c020d820730fb38296d9d6b072bd2a5350 Reviewed-on: https://go-review.googlesource.com/c/go/+/529119 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-18net: enable most tests on wasip1 and jsBryan C. Mills
To get them to pass, implement more fake syscalls. To make those syscalls easier to reason about, replace the use of sync.Cond with selectable channels. Fixes #59718. Fixes #50216. Change-Id: I135a6656f5c48f0e5c43dc4d4bcbdb48ee5535d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/526117 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Achille Roussel <achille.roussel@gmail.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-15net/http: avoid leaking goroutines when TestServerGracefulClose retriesBryan C. Mills
If the call to ReadString returns an error, the closure in testServerGracefulClose will return an error and retry the test with a longer timeout. If that happens, we need to wait for the conn.Write goroutine to complete so that we don't leak connections across tests. Updates #57084. Fixes #62643. Change-Id: Ia86c1bbd0a5e5d0aeccf4dfeb994c19d1fb10b00 Reviewed-on: https://go-review.googlesource.com/c/go/+/528398 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-15net/http: handle MethodNotAllowedJonathan Amsterdam
If no pattern matches a request, but a pattern would have matched if the request had a different method, then serve a 405 (Method Not Allowed), and populate the "Allow" header with the methods that would have succeeded. Updates #61640. Change-Id: I0ae9eb95e62c71ff7766a03043525a97099ac1bb Reviewed-on: https://go-review.googlesource.com/c/go/+/528401 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-15net: use bytealg.LastIndexByteStringapocelipes
There is no need to handwrite the "last" function, the bytealg package already provides "LastIndexByteString". Change-Id: I6000705bffe8450a10cf8f3fa716a8d4605ada1f GitHub-Last-Rev: 6627c65fb40fad96239edd28bde27a30f9f8f544 GitHub-Pull-Request: golang/go#62647 Reviewed-on: https://go-review.googlesource.com/c/go/+/527976 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-09-14net/http: synchronize tests that use reqNum countersBryan C. Mills
This suppresses the race reported in #62638. I am not 100% certain how that race happens, but here is my theory. The increment of reqNum happens before the server writes the response headers, and the server necessarily writes the headers before the client receives them. However, that write/read pair occurs through I/O syscalls rather than Go synchronization primitives, so it doesn't necessarily create a “happens before” relationship as defined by the Go memory model: although we can establish a sequence of events, that sequence is not visible to the race detector, nor to the compiler. Fixes #62638. Change-Id: I90d66ec3fc32b9b8e1f9bbf0bc2eb289b964b99b Reviewed-on: https://go-review.googlesource.com/c/go/+/528475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-09-14net/http: implement path value methods on RequestJonathan Amsterdam
Add Request.PathValue and Request.SetPathValue, and the fields on Request required to support them. Populate those fields in ServeMux.ServeHTTP. Updates #61410. Change-Id: Ic88cb865b0d865a30d3b35ece8e0382c58ef67d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/528355 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-13net/http: give ServeMux.handler a better nameJonathan Amsterdam
Change-Id: I27bb7d9d5f172a84aa31304194b8a13036b9c5d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/528275 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-13net/http: add test for registration errorsJonathan Amsterdam
Change-Id: Ice378e2f1c4cce180f020683d25070c5ae1edbad Reviewed-on: https://go-review.googlesource.com/c/go/+/528255 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-13net/http: scale rstAvoidanceDelay to reduce test flakinessBryan C. Mills
As far as I can tell, some flakiness is unavoidable in tests that race a large client request write against a server's response when the server doesn't read the full request. It does not appear to be possible to simultaneously ensure that well-behaved clients see EOF instead of ECONNRESET and also prevent misbehaving clients from consuming arbitrary server resources. (See RFC 7230 §6.6 for more detail.) Since there doesn't appear to be a way to cleanly eliminate this source of flakiness, we can instead work around it: we can allow the test to adjust the hard-coded delay if it sees a plausibly-related failure, so that the test can retry with a longer delay. As a nice side benefit, this also allows the tests to run more quickly in the typical case: since the test will retry in case of spurious failures, we can start with an aggressively short delay, and only back off to a longer one if it is really needed on the specific machine running the test. Fixes #57084. Fixes #51104. For #58398. Change-Id: Ia4050679f0777e5eeba7670307a77d93cfce856f Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-race,gotip-linux-amd64-race,gotip-windows-amd64-race Reviewed-on: https://go-review.googlesource.com/c/go/+/527196 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-09-13net/http: ServeMux handles extended patternsJonathan Amsterdam
Modify ServeMux to handle patterns with methods and wildcards. Remove the map and list of patterns. Instead patterns are registered and matched using a routing tree. We also reorganize the code around "trailing-slash redirection," the feature whereby a trailing slash is added to a path if it doesn't match an existing one. The existing code checked the map of paths twice, but searching the tree twice would be needlessly expensive. The rewrite searches the tree once, and then again only if a trailing-slash redirection is possible. There are a few omitted features in this CL, indicated with TODOs. Change-Id: Ifaef59f6c8c7b7131dc4a5d0f101cc22887bdc74 Reviewed-on: https://go-review.googlesource.com/c/go/+/528039 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-13net/http: use new Go Doc list syntaxAbhinav Gupta
This tweaks the documentation for http.Client to use the list syntax introduced in Go 1.19. Change-Id: I1f7e0256c13f57e04fc76e5e2362608c8f9f524d GitHub-Last-Rev: 11d384f9adb25605d44dbb7aaeec88fbb3b457ed GitHub-Pull-Request: golang/go#62574 Reviewed-on: https://go-review.googlesource.com/c/go/+/527335 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2023-09-12net/http: routing treeJonathan Amsterdam
This CL implements a decision tree for efficient routing. The tree holds all the registered patterns. To match a request, we walk the tree looking for a match. Change-Id: I7ed1cdf585fc95b73ef5ca2f942f278100a90583 Reviewed-on: https://go-review.googlesource.com/c/go/+/527315 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com>
2023-09-12net/http: mapping data structureJonathan Amsterdam
Our goal for the new ServeMux patterns is to match the routing performance of the existing ServeMux patterns. To achieve that we needed to optimize lookup for small maps. This CL introduces a simple data structure called a mapping that optimizes lookup by using a slice for small collections of key-value pairs, switching to a map when the collection gets large. Mappings are a core part of the routing algorithm, which uses a decision tree to match path elements. The children of a tree node are held in a mapping. Change-Id: I923b3ad1376ace2c3e3421aa9b802ad12d47c871 Reviewed-on: https://go-review.googlesource.com/c/go/+/526617 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Eli Bendersky <eliben@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-09-12net/http: pattern.conflictsWithJonathan Amsterdam
Add the conflictsWith method, which determines whether two patterns conflict with each other. Updates #61410. Change-Id: Id4f9a471dc9d0420d927a68d2864128a096b74f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/526616 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-11net/netip: add AddrPort.Compare and Prefix.CompareDavid Anderson
Fixes #61642 Change-Id: I2262855dbe75135f70008e5df4634d2cfff76550 GitHub-Last-Rev: 949685a9e426f50f37753045d7527ebcccb082e7 GitHub-Pull-Request: golang/go#62387 Reviewed-on: https://go-review.googlesource.com/c/go/+/524616 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-09-11net/http: extended routing patternsJonathan Amsterdam
This is the first of several CLs implementing the proposal for enhanced ServeMux routing, https://go.dev/issue/61410. Define a type to represent extended routing patterns and a function to parse a string into one. Updates #61410. Change-Id: I779689acf1f14b20d12c9264251f7dc002b68c49 Reviewed-on: https://go-review.googlesource.com/c/go/+/526815 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-08net: synchronize calls to Close in the withTCPConnPair test helperBryan C. Mills
withTCPConnPair is supposed to return only when both peer functions have completed. However, due to the use of "defer" it was closing the peers' connections after the synchronization point instead of before. Fixes #62542. Change-Id: I3e06c78984664172ff2d28b0fc582b8182f710f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/526977 Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Commit-Queue: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-07net: remove unused _C_GoStringTobias Klauser
It's unused since CL 466335. Change-Id: I2750f478bd2a1cde270a6273551e1434cb38b5ad Reviewed-on: https://go-review.googlesource.com/c/go/+/526076 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-05all: use ^$ instead of XXXX, NoSuchTestExists to match no testsDmitri Shuralyov
It's shorter and can't accidentally match unlikely test names. Change-Id: I96dd9da018cad1acf604f266819470278f54c128 Reviewed-on: https://go-review.googlesource.com/c/go/+/524949 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-05all: use ^TestName$ regular pattern for invoking a single testDmitri Shuralyov
Use ^ and $ in the -run flag regular expression value when the intention is to invoke a single named test. This removes the reliance on there not being another similarly named test to achieve the intended result. In particular, package syscall has tests named TestUnshareMountNameSpace and TestUnshareMountNameSpaceChroot that both trigger themselves setting GO_WANT_HELPER_PROCESS=1 to run alternate code in a helper process. As a consequence of overlap in their test names, the former was inadvertently triggering one too many helpers. Spotted while reviewing CL 525196. Apply the same change in other places to make it easier for code readers to see that said tests aren't running extraneous tests. The unlikely cases of -run=TestSomething intentionally being used to run all tests that have the TestSomething substring in the name can be better written as -run=^.*TestSomething.*$ or with a comment so it is clear it wasn't an oversight. Change-Id: Iba208aba3998acdbf8c6708e5d23ab88938bfc1e Reviewed-on: https://go-review.googlesource.com/c/go/+/524948 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-04net: respect hosts file when resolving names for WindowsNikita Vaniasin
Fixes #57757. Change-Id: I896dae8e5905ae98539ab83c9379fd1c9886d44a Reviewed-on: https://go-review.googlesource.com/c/go/+/467335 Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com> Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-09-01net: deflake TestDialTimeout on windowsBryan C. Mills
The time granularity on windows is large enough that setting even an implausibly small timeout still gives ConnectEx enough time to succeed before the timeout expires. That causes TestDialTimeout to sometimes flake, because it expects to be able to provoke a timeout using some nonzero duration. This change takes a two-pronged approach to address the problem: 1. We can set a deadline on the FD more aggressively. (If the Context has already expired, or the deadline is already known, we can go ahead and set it on the fd without waiting for a background goroutine to get around to it.) 2. We can reintroduce a test hook to ensure that Dial takes a measurable amount of time before it completes, so that setting an implausibly short deadline sets that deadline in the past instead of the future. Together, these reduce the flake rate on a windows-amd64-longtest gomote from around 1-in-10 to less than 1-in-2000. For #62377. Change-Id: I03975c32f61fffa9f6f84efb3c474a01ac5a0d1e Reviewed-on: https://go-review.googlesource.com/c/go/+/524936 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-31net: remove unused errTimedoutTobias Klauser
It's unused since CL 524055. Change-Id: I767eac6a66379e67337e24051e5f79aa027e9fad Reviewed-on: https://go-review.googlesource.com/c/go/+/524715 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-30net: retry TestDialTimeout subtests with progressively shorter timeoutsBryan C. Mills
The LUCI builders seem to show that the failure mode in #62359 is not specific to windows/arm64, but it occurs to me that we ought to be able to eventually retry by making the timeout so short that the remote end can't possibly respond in time (discounting the possibility that the kernel itself might short-circuit the loopback address). For #62377. Updates #62359. Updates #56876. Change-Id: I1fb5fa4f2a5d2cfe35465f34248ed9a035f91f4f Reviewed-on: https://go-review.googlesource.com/c/go/+/524595 Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-30internal/poll, net: use (*FD).SetsockoptInet4Addr in ↵Tobias Klauser
setIPv4MulticastInterface on windows Change-Id: Ic29d15bf62d8e693ca969354b415d958823bf41d Reviewed-on: https://go-review.googlesource.com/c/go/+/523915 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: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-08-30net: skip TestDialTimeout subtests on Windows if Dial returns WSAECONNREFUSEDBryan C. Mills
Since we have only seen this failure mode on windows/arm64, we do not skip on the Go project's windows/amd64 builders so that we will be more likely to find out whether this failure mode is specific to arm64. Also simplify the ECONNRESET check, since I've remembered that the error_*_test.go files exist. Fixes #62359. Updates #56876. Change-Id: I17bd678486f3d3ec3363a45986a711f570b013d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/524455 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-08-29net: avoid internal hooks in TestDialTimeoutBryan C. Mills
TestDialTimeout has historically been very flaky (#11872, #13144, #22896, and now #56876), apparently in part due to implementation details of the socktest package it relies on. In reviewing CL 467335, I noticed that TestDialTimeout is the last remaining use of testHookDialChannel (added for #5349), and that that hook no longer has any effect for Unix and Windows. As an experiment, I tried removing both that hook and the call to time.Sleep in the socktest filter, and to my surprise the test continued to pass. That greatly undermined my confidence in the test, since it appears that the “timeout” behavior it observes is caused by the socktest filter injecting an error rather than anything in the net package proper actually timing out. To restore confidence in the test, I think it should be written against only the public API of the net package, and should test the publicly-documented behaviors. This change implements that approach. Notably, when a timeout is set on a Dial call, that does not guarantee that the listener will actually call Accept on the connection before the timeout occurs: the kernel's network stack may preemptively accept and buffer the connection on behalf of the listener. To avoid test flakiness, the test must tolerate (and leave open) those spurious connections: when the kernel has accepted enough of them, it will start to block new connections until the buffered connections have been accepted, and the expected timeout behavior will occur. This also allows the test to run much more quickly and in parallel: since we are relying on real timeouts instead of injected calls to time.Sleep, we can set the timeouts to be much shorter and run concurrently with other public-API tests without introducing races. Fixes #56876. Change-Id: I90dcb2ed70976e70857ca29c253ed760cb078a4c Reviewed-on: https://go-review.googlesource.com/c/go/+/524055 TryBot-Bypass: Bryan Mills <bcmills@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>