PDGGK opened a new pull request, #3741:
URL: https://github.com/apache/brpc/pull/3741
### What problem does this PR solve?
Issue Number: resolve #2283
Problem Summary:
A channel initialized with a load balancer and an IPv6 address in an
`http://` URL never finds a server. With a brpc server listening on
`[::1]:8765`, `Init("http://[::1]:8765", "rr", &options)` returns 0, but every
call then fails with `[E61]Fail to select server from http://[::1]:8765 lb=rr`,
and the naming service logs `No port after colon in '[::1]:8765'`. `Init` with
the same URL and no load balancer succeeds, because the single-server path
already parses bracketed addresses.
`DomainNamingService::GetServers` (registered for `http`, `https` and
`redis`) copies the host up to the first `:`, so for `[::1]:8765` the host is
`[` and the port parse fails. The address from the issue,
`[fdbd:dc03:ff:501:b783:830f:f0f5:aa6a]:2280`, fails the same way.
### What is changed and the side effects?
Changed:
When the name starts with `[`, the host runs to the matching `]`. After it
only `:port`, a `/path` or the end of the string is accepted, and the port is
parsed as before. The bracketed address goes straight to `butil::str2endpoint`,
the parser the single-server path uses, without a DNS lookup. That does not
depend on `-dns_support_ipv6`, since there is no name to resolve. Host names
and IPv4 addresses take the same path as before.
`NamingServiceTest.domain_with_ipv6_address` covers an address with a port,
the address from the issue, a trailing path, the default port, and five
malformed forms (missing `]`, empty port, garbage after `]`, port out of range,
not an address). Without the change it fails at the first assertion with `Which
is: -1` and the same `No port after colon` log.
I tested in Docker on Ubuntu 22.04 (gcc 11.4, CMake build with
`BUILD_UNIT_TESTS=ON`). All 14 tests in `brpc_naming_service_unittest` pass
with the change. Without it, the other 13 pass and the new one fails. A small
client and server program on `[::1]:8765` gets `OK` from `/health` through
`"rr"` with the change, and the E61 error above without it.
`domain_naming_service.cpp` also compiles with the CI warning flags plus
`-Werror` under gcc 11.4 and clang 14. I did not run the Make or Bazel builds
or the rest of the test suite, and I did not test on macOS.
Side effects:
- Performance effects: none. A bracketed address skips the DNS lookup it
could never pass anyway.
- Breaking backward compatibility: no. A name that starts with `[` could not
be resolved before.
---
### Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow [Contributor Covenant Code of
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]