Skip to content
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

[Bug] 开启tun并使用system栈时,会遇到map读写并发冲突,导致程序崩溃 #707

Closed
5 of 6 tasks
athenakia opened this issue Aug 27, 2023 · 3 comments
Closed
5 of 6 tasks

Comments

@athenakia
Copy link

Verify steps

  • 确保你使用的是本仓库最新的的 clash 或 clash Alpha 版本 Ensure you are using the latest version of Clash or Clash Premium from this repository.
  • 如果你可以自己 debug 并解决的话,提交 PR 吧 Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • 我已经在 Issue Tracker 中找过我要提出的问题 I have searched on the issue tracker for a related issue.
  • 我已经使用 Alpha 分支版本测试过,问题依旧存在 I have tested using the dev branch, and the issue still exists.
  • 我已经仔细看过 Documentation 并无法自行解决问题 I have read the documentation and was unable to solve the issue.
  • 这是 Clash 核心的问题,并非我所使用的 Clash 衍生版本(如 OpenClash、KoolClash 等)的特定问题 This is an issue of the Clash core per se, not to the derivatives of Clash, like OpenClash or KoolClash.

Clash version

v1.15.1

What OS are you seeing the problem on?

No response

Clash config

port: 7890
socks-port: 7891
allow-lan: false
mode: Rule
log-level: debug
external-controller: 127.0.0.1:9090
proxies:
# ...
proxy-groups:
# ...
rules:
# ...

tun:
  enable: true
  stack: system
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - any:53

Clash log

fatal error: concurrent map writes

goroutine 9312 [running]:
github.com/Dreamacro/clash/adapter.(*Proxy).URLTest.func1()
	/source/adapter/adapter.go:227 +0x2c8
github.com/Dreamacro/clash/adapter.(*Proxy).URLTest(0x1400023fdc0, {0x101be17c8?, 0x1400051d830}, {0x140006ac900, 0x23}, {0x0?, 0x0, 0x1016c410c?}, 0x1)
	/source/adapter/adapter.go:306 +0x6ac
github.com/Dreamacro/clash/hub/route.getProxyDelay({0x101be0960, 0x140002ac1c0}, 0x1400099a100)
	/source/hub/route/proxies.go:128 +0x274
net/http.HandlerFunc.ServeHTTP(0x101a14300?, {0x101be0960?, 0x140002ac1c0?}, 0x140003030f6?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0x1400020e300, {0x101be0960, 0x140002ac1c0}, 0x1400099a100)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:444 +0x234
net/http.HandlerFunc.ServeHTTP(0x101be1800?, {0x101be0960?, 0x140002ac1c0?}, 0x1400052b7b0?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/Dreamacro/clash/hub/route.findProxyByName.func1({0x101be0960, 0x140002ac1c0}, 0x1400099a000)
	/source/hub/route/proxies.go:58 +0x210
net/http.HandlerFunc.ServeHTTP(0x101be1800?, {0x101be0960?, 0x140002ac1c0?}, 0x1400052b780?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/Dreamacro/clash/hub/route.parseProxyName.func1({0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/source/hub/route/proxies.go:42 +0x188
net/http.HandlerFunc.ServeHTTP(0x1400051d710?, {0x101be0960?, 0x140002ac1c0?}, 0x1400012b628?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0x1400020e300, {0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:73 +0x328
github.com/go-chi/chi/v5.(*Mux).Mount.func1({0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:316 +0x1ec
net/http.HandlerFunc.ServeHTTP(0x101a14300?, {0x101be0960?, 0x140002ac1c0?}, 0x140006d0b28?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0x1400020e2a0, {0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:444 +0x234
net/http.HandlerFunc.ServeHTTP(0x1400051d710?, {0x101be0960?, 0x140002ac1c0?}, 0x1400012b7b8?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0x1400020e2a0, {0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:73 +0x328
github.com/go-chi/chi/v5.(*Mux).Mount.func1({0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:316 +0x1ec
net/http.HandlerFunc.ServeHTTP(0x1400012b908?, {0x101be0960?, 0x140002ac1c0?}, 0x14000220420?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/Dreamacro/clash/hub/route.authentication.func1({0x101be0960?, 0x140002ac1c0?}, 0x1?)
	/source/hub/route/server.go:164 +0x2b0
net/http.HandlerFunc.ServeHTTP(0x14000220420?, {0x101be0960?, 0x140002ac1c0?}, 0x1400032e0a0?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/chi/v5.(*ChainHandler).ServeHTTP(0x101a14300?, {0x101be0960?, 0x140002ac1c0?}, 0x14000242ea0?)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/chain.go:31 +0x30
github.com/go-chi/chi/v5.(*Mux).routeHTTP(0x1400020e180, {0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:444 +0x234
net/http.HandlerFunc.ServeHTTP(0x1400021e0a0?, {0x101be0960?, 0x140002ac1c0?}, 0x1400037df00?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/cors.(*Cors).Handler.func1({0x101be0960, 0x140002ac1c0}, 0x1400037df00)
	/go/pkg/mod/github.com/go-chi/cors@v1.2.1/cors.go:228 +0x1e4
net/http.HandlerFunc.ServeHTTP(0x101be1758?, {0x101be0960?, 0x140002ac1c0?}, 0x102427ef0?)
	/usr/local/go/src/net/http/server.go:2122 +0x38
github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0x1400020e180, {0x101be0960, 0x140002ac1c0}, 0x1400037de00)
	/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.10/mux.go:90 +0x2e4
net/http.serverHandler.ServeHTTP({0x14000fa66f0?}, {0x101be0960, 0x140002ac1c0}, 0x1400037de00)
	/usr/local/go/src/net/http/server.go:2936 +0x2d8
net/http.(*conn).serve(0x1400023c510, {0x101be1800, 0x14000221260})
	/usr/local/go/src/net/http/server.go:1995 +0x560
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:3089 +0x520

goroutine 1 [chan receive, 32 minutes]:
main.main()
	/source/main.go:120 +0x8fc

goroutine 6 [chan receive]:
github.com/Dreamacro/clash/common/observable.(*Observable[...]).process(0x101bf2980)
	/source/common/observable/observable.go:16 +0x48
created by github.com/Dreamacro/clash/common/observable.NewObservable[...]
	/source/common/observable/observable.go:63 +0xec

goroutine 7 [chan receive]:
github.com/Dreamacro/clash/tunnel/statistic.(*Manager).handle(0x140000924e0)
	/source/tunnel/statistic/manager.go:115 +0x88
created by github.com/Dreamacro/clash/tunnel/statistic.init.0
	/source/tunnel/statistic/manager.go:26 +0x204

goroutine 8 [chan receive]:
github.com/Dreamacro/clash/tunnel.process()
	/source/tunnel/tunnel.go:204 +0x80
created by github.com/Dreamacro/clash/tunnel.init.0
	/source/tunnel/tunnel.go:89 +0x24

goroutine 18 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 19 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 20 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 21 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 22 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 23 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 24 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 25 [chan receive]:
github.com/Dreamacro/clash/tunnel.processUDP()
	/source/tunnel/tunnel.go:185 +0x3c
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:200 +0x48

goroutine 11865 [select]:
reflect.rselect({0x14000d6b858, 0x1, 0x14000c88c00?})
	/usr/local/go/src/runtime/select.go:589 +0x294
reflect.Select({0x140002f0340?, 0x1, 0x1?})
	/usr/local/go/src/reflect/value.go:3052 +0x468
github.com/sagernet/sing/common.SelectContext({0x140003e2800, 0x2, 0x101a3a220?})
	/go/pkg/mod/github.com/metacubex/sing@v0.0.0-20230714010500-e24664dc75a7/common/context.go:13 +0x1ac
github.com/sagernet/sing/common/task.(*Group).RunContextList(0x1400047c090, {0x14000d6bb58?, 0x14000f1c560?, 0x102446ce0?})
	/go/pkg/mod/github.com/metacubex/sing@v0.0.0-20230714010500-e24664dc75a7/common/task/task.go:89 +0x370
github.com/sagernet/sing/common/bufio.CopyConnContextList({0x14000d6bb58, 0x1, 0x1}, {0x101be8728?, 0x14000f1c560}, {0x129fc72e0?, 0x1400051dec0})
	/go/pkg/mod/github.com/metacubex/sing@v0.0.0-20230714010500-e24664dc75a7/common/bufio/copy.go:252 +0x744
github.com/sagernet/sing/common/bufio.CopyConn(...)
	/go/pkg/mod/github.com/metacubex/sing@v0.0.0-20230714010500-e24664dc75a7/common/bufio/copy.go:212
github.com/Dreamacro/clash/common/net.Relay({0x101be8728?, 0x14000f1c560?}, {0x129fc72e0?, 0x1400051dec0?})
	/source/common/net/sing.go:39 +0xf8
github.com/Dreamacro/clash/tunnel.handleSocket({0x101bdefe0?, 0x14000f1c580?}, {0x129fc72e0, 0x1400051dec0})
	/source/tunnel/connection.go:89 +0x4c
github.com/Dreamacro/clash/tunnel.handleTCPConn({0x101bdefe0, 0x14000f1c580})
	/source/tunnel/tunnel.go:530 +0xbec
created by github.com/Dreamacro/clash/tunnel.process
	/source/tunnel/tunnel.go:209 +0x120

goroutine 11 [IO wait]:
internal/poll.runtime_pollWait(0x129cb2718, 0x72)
	/usr/local/go/src/runtime/netpoll.go:306 +0xa0
internal/poll.(*pollDesc).wait(0x14000228100?, 0x0?, 0x0)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:84 +0x28
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Accept(0x14000228100)
	/usr/local/go/src/internal/poll/fd_unix.go:614 +0x250
net.(*netFD).accept(0x14000228100)
	/usr/local/go/src/net/fd_unix.go:172 +0x28
net.(*TCPListener).accept(0x14000210b70)
	/usr/local/go/src/net/tcpsock_posix.go:148 +0x28
net.(*TCPListener).Accept(0x14000210b70)
	/usr/local/go/src/net/tcpsock.go:297 +0x2c
net/http.(*Server).Serve(0x1400024c000, {0x101be0750, 0x14000210b70})
	/usr/local/go/src/net/http/server.go:3059 +0x304
net/http.Serve(...)
	/usr/local/go/src/net/http/server.go:2581
github.com/Dreamacro/clash/hub/route.Start({0x14000043e60, 0xe}, {0x0, 0x0}, {0x0?, 0x0?}, {0x0, 0x0}, {0x0, 0x0}, ...)
	/source/hub/route/server.go:149 +0x60c
created by github.com/Dreamacro/clash/hub.Parse
	/source/hub/hub.go:46 +0x264

goroutine 12 [IO wait]:
internal/poll.runtime_pollWait(0x129cb2628, 0x72)
	/usr/local/go/src/runtime/netpoll.go:306 +0xa0
internal/poll.(*pollDesc).wait(0x14000531800?, 0x100c67908?, 0x0)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:84 +0x28
internal/poll.(*pollDesc).waitRead(...)
	/usr/local/go/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Accept(0x14000531800)
	/usr/local/go/src/internal/poll/fd_unix.go:614 +0x250
net.(*netFD).accept(0x14000531800)
	/usr/local/go/src/net/fd_unix.go:172 +0x28
net.(*TCPListener).accept(0x140004557e8)
	/usr/local/go/src/net/tcpsock_posix.go:148 +0x28
net.(*TCPListener).Accept(0x140004557e8)
	/usr/local/go/src/net/tcpsock.go:297 +0x2c
github.com/Dreamacro/clash/listener/http.NewWithAuthenticate.func1()
	/source/listener/http/server.go:61 +0x60
created by github.com/Dreamacro/clash/listener/http.NewWithAuthenticate
	/source/listener/http/server.go:59 +0x288

Description

按照上述配置案例启动clash.meta核心一段时间后,会出现map读写并发冲突导致的致命错误,程序整个崩溃,Golang默认的map不支持并发读写操作,需要额外维护一个sync.RWMutex/sync.Mutex锁类型,或者使用sync.Map类型替代内置的map。

目前只在tun开启并使用system栈情况下观察到。

@yaoqiangpersonal
Copy link

一样问题,不过我不知道在哪里可以看到这些日志,我使用system 模式的时候,下载规则的时候就直接卡死了。偶尔能开起来,除了本机,下游的机器访问也没有任何日志。使用gvisor 就没有问题。

@athenakia
Copy link
Author

gvisor确实兼容性好很多,不过性能一般般,经常一卡一卡的。

@athenakia
Copy link
Author

一样问题,不过我不知道在哪里可以看到这些日志,我使用system 模式的时候,下载规则的时候就直接卡死了。偶尔能开起来,除了本机,下游的机器访问也没有任何日志。使用gvisor 就没有问题。

我是直接运行clash.meta核心的,日志直接在控制台输出。如果你用的是一些GUI图形界面客户端,可能需要在软件里面找找日志目录。

Larvan2 added a commit that referenced this issue Aug 31, 2023
stitchrs pushed a commit that referenced this issue Aug 31, 2023
xianren78 pushed a commit to xianren78/Clash.Meta that referenced this issue Sep 1, 2023
wwqgtxx pushed a commit that referenced this issue Sep 1, 2023
@Larvan2 Larvan2 closed this as completed Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants