-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix IPv6 connectivity by binding servers to :: instead of 0.0.0.0 #2921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ export class HttpServerService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async initialize(expressApp: express.Application, port: number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new Promise((resolve, reject) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.server = expressApp.listen(port, '0.0.0.0', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.server = expressApp.listen(port, '::', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning 在不少现代 Linux 上,绑定到 :: 会通过 IPv4-mapped IPv6 支持 IPv4;但在某些系统/配置(如 sysctl net.ipv6.bindv6only=1、部分容器/发行版默认行为、或 Windows 的差异行为)下,绑定到 :: 可能只接受 IPv6,导致 IPv4 客户端无法访问。当前实现没有提供回退到 0.0.0.0 的逻辑,因此存在兼容性风险。 建议: 建议在绑定失败或检测到仅 IPv6 的环境时,增加一个明确的回退策略:优先尝试 '::',若监听错误(如 EADDRNOTAVAIL / EAFNOSUPPORT 等)则回退到 '0.0.0.0';或提供配置项允许用户选择绑定地址。
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Logger.debug(`✌️ HTTP service started successfully`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metricsService.record('http_service_start', 1, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| port: port.toString(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning
与 HTTP 类似,gRPC 绑定到 [::]:port 是否同时接受 IPv4 取决于运行环境的 dual-stack 行为。当前仅尝试 IPv6 绑定,若环境不支持 IPv6 会直接抛错;若环境为 v6-only,也可能导致 IPv4 客户端无法连接。
建议: 建议优先尝试 [::]:port,失败则回退到 0.0.0.0:port;或增加配置项允许显式指定 bind address,并在日志中打印实际绑定地址,便于排障。