-
Notifications
You must be signed in to change notification settings - Fork 237
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
fix: panic due to goroutine setting returned error #748
fix: panic due to goroutine setting returned error #748
Conversation
@@ -68,7 +68,7 @@ func ResolveIp46(ctx context.Context, dialer netproxy.Dialer, dns netip.AddrPort | |||
}() | |||
var e error | |||
addrs6, e = ResolveNetip(ctx6, dialer, dns, host, dnsmessage.TypeAAAA, network) | |||
if err != nil && !errors.Is(e, context.Canceled) { | |||
if e != nil && !errors.Is(e, context.Canceled) { |
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.
之前的逻辑,当 err != nil 的时候,e 可能是 nil,此时 errors.Is(nil, ...) 就恐慌了。这种手滑写错变量,还有 == nil 写反成 != nil 之类的都很容易被忽视 😹
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.
是的!我用的 ide 自动补全成的 err
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.
@jschwinger233 不过 errors.Is(nil, ...) 不会恐慌,这个是检查的时候顺手修的
目前没有复现panic,但是发现在我的所有机器上使用这条更改 97f41ec...278d6da 的dae,网络环境都会从原先的没有dns污染变为有dns污染,具体表现为应用这条更改后curl和chrome内解析 zh.wikipedia.org 会解析到facebook地址,然后 测试前后的rev是 97f41ec (也就是现在的main HEAD,正常)和 278d6da(异常) 我的dae配置 https://github.com/oluceps/nixos-config/blob/7df068e4e147f9c639653aa4f5966c0dc20c8988/repack/dae.nix#L21 节点全部是本地socks5 没开dnsmasq没开systemd-resolved,网络使用systemd-networkd管理,dnsproxy listen 53 |
@oluceps 换回去就好了吗 |
是的,试验多次 换回去就一切正常了 |
再次试验百分百复现,dae revision 278d6da
请求时dae的debug日志,从curl开始请求到请求结束:
curl的详细信息:
dnsproxy配置
换回 97f41ec 一切正常 |
@oluceps 已更新,烦请看看是否修复 dns 污染问题 |
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.
🧪 Since the PR has been fully tested, please consider merging it.
@@ -140,6 +140,25 @@ func ResolveNS(ctx context.Context, d netproxy.Dialer, dns netip.AddrPort, host | |||
return records, nil | |||
} | |||
|
|||
func ResolveSOA(ctx context.Context, d netproxy.Dialer, dns netip.AddrPort, host string, network string) (records []string, err error) { |
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.
这个函数。。好像没有被用到?
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.
是的忘了删了,先留着吧
Background
返回值显式给出变量名时,例如 (err error),如果函数内有 go routine 设置 err 的值,则有概率会导致 racing 风险,导致 errors.Is / errors.Unwrap 出错。
复现方法:
多运行几次即可复现。
其中的 sniffing.IsSniffingError 定义如下:
猜测:存在编译器优化使得类似 std::move,函数内外的 err 是同一个地址。
修复:不要在 go routine 里直接设置 err 的值。
Checklist
Full Changelogs
Issue Reference
Closes #685
Closes #693
Closes #735
Closes #745
Test Result