sing-box icon indicating copy to clipboard operation
sing-box copied to clipboard

在连接突然断开的情况 DOH 相关的连接不会主动断开和重试。

Open daminit opened this issue 1 year ago • 5 comments

操作系统

Linux

系统版本

Linux hytron 6.12.41+deb13-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.41-1 (2025-08-12) x86_64 GNU/Linux

安装类型

sing-box 原始命令行程序

如果您使用图形客户端程序,请提供该程序版本。

No response

版本

sing-box version 1.12.4

Environment: go1.25.0 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale
Revision: 980e96250bf693bb8400183d6a05665da8ad9d03
CGO: disabled

描述

在有双栈网络的情况下,如果一个 DOH (HTTP2) 连接使用的其中一个栈(在例子中使用的IPv6栈) 。如果这个网络栈突然断开且没有在断开相关连接的情况下,DOH不会去尝试使用另一个栈(在例子中是IPv4) 或者去新建一个连接。

现在还不确定是否所有的带有多路复用的连接是否都具有相同的问题,现在只尝试了DOH ,如果需要尝试其他相关带有多路复用的连接我可以提供测试。

重现方式

sing-box 配置文件

{
  "log":{
    "level":"trace"
  },
  "dns": {
    "servers": [
      {
        "type":"udp",
        "tag":"bootstrap",
        "server":"8.8.8.8"
      },
      {
        "type": "https",
        "tag": "internal",
        "server": "dns.google",
        "domain_resolver":{
          "server":"bootstrap",
          "strategy":"prefer_ipv6"
        }
      }
    ],
    "final":"internal"
  },
  "inbounds":[
    {"type":"direct","tag":"dns-in","listen":"127.0.0.1","listen_port":20853}
  ],
  "route":{
    "rules":[
      {
        "inbound":["dns-in"],
        "action":"hijack-dns"
      }
    ]
  },
  "outbounds":[
    {"tag":"direct","type":"direct","domain_resolver":"internal"}
  ]
}

下面是重现命令过程。

root@hytron:~# dig google.com @127.0.0.1 -p 20853

; <<>> DiG 9.20.11-4-Debian <<>> google.com @127.0.0.1 -p 20853
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11052
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0x00f9, udp: 512
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             249     IN      A       142.250.71.142

;; Query time: 59 msec
;; SERVER: 127.0.0.1#20853(127.0.0.1) (UDP)
;; WHEN: Wed Sep 10 11:52:49 HKT 2025
;; MSG SIZE  rcvd: 65

root@hytron:~# ip -6 rule add unreachable
root@hytron:~# ip -6 rule
0:      from all lookup local
32765:  from all unreachable
32766:  from all lookup main
root@hytron:~# dig google.com @127.0.0.1 -p 20853
;; communications error to 127.0.0.1#20853: timed out
;; communications error to 127.0.0.1#20853: timed out
;; communications error to 127.0.0.1#20853: timed out

; <<>> DiG 9.20.11-4-Debian <<>> google.com @127.0.0.1 -p 20853
;; global options: +cmd
;; no servers could be reached

日志

INFO[0000] network: updated default interface ens18, index 2
INFO[0000] inbound/direct[dns-in]: tcp server started at 127.0.0.1:20853
INFO[0000] inbound/direct[dns-in]: udp server started at 127.0.0.1:20853
INFO[0000] sing-box started (0.00s)
INFO[0002] [1615442623 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:41283
INFO[0002] [1615442623 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0002] [1615442623 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0002] [1615442623 1ms] dns: exchange google.com. IN A
DEBUG[0002] [1615442623 1ms] dns: lookup domain dns.google
DEBUG[0002] [1615442623 3ms] dns: exchanged dns.google NOERROR 531
DEBUG[0002] [1615442623 3ms] dns: exchanged AAAA dns.google. 531 IN AAAA 2001:4860:4860::8888
DEBUG[0002] [1615442623 3ms] dns: exchanged AAAA dns.google. 531 IN AAAA 2001:4860:4860::8844
DEBUG[0002] [1615442623 4ms] dns: exchanged dns.google NOERROR 75
DEBUG[0002] [1615442623 4ms] dns: exchanged A dns.google. 75 IN A 8.8.8.8
DEBUG[0002] [1615442623 4ms] dns: exchanged A dns.google. 75 IN A 8.8.4.4
DEBUG[0002] [1615442623 4ms] dns: lookup succeed for dns.google: 2001:4860:4860::8888 2001:4860:4860::8844 8.8.8.8 8.8.4.4
DEBUG[0002] [1615442623 59ms] dns: exchanged google.com NOERROR 249
INFO[0002] [1615442623 60ms] dns: exchanged A google.com. 249 IN A 142.250.71.142
INFO[0002] [1615442623 60ms] dns: exchanged OPT OPT PSEUDOSECTION: EDNS: version 0 flags: MBZ: 0x00f9, udp: 512
INFO[0024] [3886372980 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:42613
INFO[0024] [3886372980 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0024] [3886372980 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0024] [3886372980 0ms] dns: exchange google.com. IN A
INFO[0029] [2666407251 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:52391
INFO[0029] [2666407251 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0029] [2666407251 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0029] [2666407251 0ms] dns: exchange google.com. IN A
ERROR[0034] [3886372980 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded
INFO[0034] [4105595054 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:58209
INFO[0034] [4105595054 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0034] [4105595054 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0034] [4105595054 0ms] dns: exchange google.com. IN A
ERROR[0039] [2666407251 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded
ERROR[0044] [4105595054 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded

支持我们

完整性要求

  • [x] 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • [x] 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
  • [x] 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
  • [x] 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。

daminit avatar Sep 10 '25 04:09 daminit

https://github.com/SagerNet/sing-box/blob/3aaab0be6921b309419e4eec3e35dbfc6f4186dc/dns/transport/https.go#L180-L192 should check context.DeadlineExceeded instead or check both? See also https://go-review.googlesource.com/c/go/+/546275.

dyhkwong avatar Sep 10 '25 09:09 dyhkwong

Try https://github.com/SagerNet/sing-box/commit/1344f01a1dfc86b2e82e229284fdfe6813a94ee5

nekohasekai avatar Sep 10 '25 09:09 nekohasekai

已经修复了。但是编译过程中有一个报错 route/route.go 里面的 import os 没有删除,导致编译报错。

在下一个正式版本发布的时候我会关闭这个Issue。

daminit avatar Sep 10 '25 13:09 daminit

贴一个修复后的处理过程和日志。

root@hytron:~/sb-test# dig google.com @127.0.0.1 -p 20853

; <<>> DiG 9.20.11-4-Debian <<>> google.com @127.0.0.1 -p 20853
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11266
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0x012c, udp: 512
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             300     IN      A       142.250.71.174

;; Query time: 91 msec
;; SERVER: 127.0.0.1#20853(127.0.0.1) (UDP)
;; WHEN: Wed Sep 10 21:45:26 HKT 2025
;; MSG SIZE  rcvd: 65

root@hytron:~/sb-test# ip -6 rule add unreachable
root@hytron:~/sb-test# dig google.com @127.0.0.1 -p 20853
;; communications error to 127.0.0.1#20853: timed out
;; communications error to 127.0.0.1#20853: timed out

; <<>> DiG 9.20.11-4-Debian <<>> google.com @127.0.0.1 -p 20853
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32809
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0x0018, udp: 512
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             24      IN      A       142.250.197.174

;; Query time: 299 msec
;; SERVER: 127.0.0.1#20853(127.0.0.1) (UDP)
;; WHEN: Wed Sep 10 21:45:48 HKT 2025
;; MSG SIZE  rcvd: 65

日志

INFO[0000] network: updated default interface ens18, index 2
INFO[0000] inbound/direct[dns-in]: tcp server started at 127.0.0.1:20853
INFO[0000] inbound/direct[dns-in]: udp server started at 127.0.0.1:20853
INFO[0000] sing-box started (0.00s)
INFO[0004] [578861763 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:33585
INFO[0004] [578861763 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0004] [578861763 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0004] [578861763 1ms] dns: exchange google.com. IN A
DEBUG[0004] [578861763 1ms] dns: lookup domain dns.google
DEBUG[0004] [578861763 3ms] dns: exchanged dns.google NOERROR 288
DEBUG[0004] [578861763 3ms] dns: exchanged AAAA dns.google. 288 IN AAAA 2001:4860:4860::8844
DEBUG[0004] [578861763 3ms] dns: exchanged AAAA dns.google. 288 IN AAAA 2001:4860:4860::8888
DEBUG[0004] [578861763 3ms] dns: exchanged dns.google NOERROR 518
DEBUG[0004] [578861763 4ms] dns: exchanged A dns.google. 518 IN A 8.8.8.8
DEBUG[0004] [578861763 4ms] dns: exchanged A dns.google. 518 IN A 8.8.4.4
DEBUG[0004] [578861763 4ms] dns: lookup succeed for dns.google: 2001:4860:4860::8844 2001:4860:4860::8888 8.8.8.8 8.8.4.4
DEBUG[0004] [578861763 88ms] dns: exchanged google.com NOERROR 300
INFO[0004] [578861763 89ms] dns: exchanged A google.com. 300 IN A 142.250.71.174
INFO[0004] [578861763 89ms] dns: exchanged OPT OPT PSEUDOSECTION: EDNS: version 0 flags: MBZ: 0x012c, udp: 512
INFO[0016] [3969941399 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:54525
INFO[0016] [3969941399 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0016] [3969941399 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0016] [3969941399 0ms] dns: exchange google.com. IN A
INFO[0021] [2599621233 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:57984
INFO[0021] [2599621233 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0021] [2599621233 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0021] [2599621233 0ms] dns: exchange google.com. IN A
ERROR[0026] [3969941399 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded
INFO[0026] [3533601139 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:34176
INFO[0026] [3533601139 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0026] [3533601139 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0026] [3533601139 1ms] dns: exchange google.com. IN A
DEBUG[0026] [3533601139 299ms] dns: exchanged google.com NOERROR 24
INFO[0026] [3533601139 299ms] dns: exchanged A google.com. 24 IN A 142.250.197.174
INFO[0026] [3533601139 299ms] dns: exchanged OPT OPT PSEUDOSECTION: EDNS: version 0 flags: MBZ: 0x0018, udp: 512
ERROR[0031] [2599621233 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded

daminit avatar Sep 10 '25 13:09 daminit

fixed : https://github.com/SagerNet/sing-box/releases/tag/v1.12.5

daminit avatar Sep 11 '25 04:09 daminit