Closed 4-FLOSS-Free-Libre-Open-Source-Software closed 4 months ago
Please describe when the error occurs, when the program starts running or after running for a while?
it was early after starting.
it was early after starting.
Cloud you provide your configuration?
Cloud you provide your configuration?
what part of it is important? It is big configuration: >200k
The same configuration was running smooth for week beforehand.
Cloud you provide your configuration?
what part of it is important? It is big configuration: >200k
The same configuration was running smooth for week beforehand.
I have no clue, the code in question hasn't been changed in three months.
Cloud you provide your configuration?
what part of it is important? It is big configuration: >200k The same configuration was running smooth for week beforehand.
I have no clue, the code in question hasn't been changed in three months.
I updated the logs to include the beginning of error occurred.
@4-FLOSS-Free-Libre-Open-Source-Software @xiaokangwang @AkinoKaede I've done some investigating. I'm not sure why goroutine is used here https://github.com/v2fly/v2ray-core/blob/acbb5e6e0820fc113c476bd25386a098abcac07c/app/dispatcher/default.go#L216 this goroutine concurrent map read and map write.
I prefer the first solution, but the logic here is very complicated, I didn't dig deeper, I'm not sure if here can not use goroutine, I hope it can help you.
I tried the unstable release V2Ray 5.7.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.20.4 linux/amd64) and it is still crashing multiple times every day with this error.
@4-FLOSS-Free-Libre-Open-Source-Software @xiaokangwang @AkinoKaede I've done some investigating. I'm not sure why goroutine is used here
this goroutine concurrent map read and map write.
- nonuse goroutine
- add mutex to protect WeightManager.cache
I prefer the first solution, but the logic here is very complicated, I didn't dig deeper, I'm not sure if here can not use goroutine, I hope it can help you.
@4-FLOSS-Free-Libre-Open-Source-Software You can try modify go d.routedDispatch(ctx, outbound, destination) => d.routedDispatch(ctx, outbound, destination) rebuild it
@4-FLOSS-Free-Libre-Open-Source-Software You can try modify go d.routedDispatch(ctx, outbound, destination) => d.routedDispatch(ctx, outbound, destination) rebuild it
I tried that. But then unfortunately, DNS reproducible stops working with same config but works with release v5.7.1.
cc @xiaokangwang
@4-FLOSS-Free-Libre-Open-Source-Software You can try modify go d.routedDispatch(ctx, outbound, destination) => d.routedDispatch(ctx, outbound, destination) rebuild it
I tried that. But then unfortunately, DNS reproducible stops working with same config but works with release v5.7.1.
I guess the reason for this is a certain function in upper function stack calls d.routedDispatch()
in a new goroutine so removing the go
here cannot fix the race condition, though the function to be found yet.
I tried to reproduce that showd above by constructing a config file, but I failed. But I think the bug might be fixed by adding a lock to the data structure v2ray/app/router/weight.go:WeightManager
to protect cache
field, specifically:
diff --git a/app/router/weight.go b/app/router/weight.go
index ec7711b9..8d217241 100644
--- a/app/router/weight.go
+++ b/app/router/weight.go
type weightScaler func(value, weight float64) float64
@@ -26,16 +27,19 @@ type WeightManager struct {
...
+ mu sync.Mutex
}
// Get gets the weight of specified tag
func (s *WeightManager) Get(tag string) float64 {
+ s.mu.Lock()
weight, ok := s.cache[tag]
...
s.cache[tag] = weight
+ s.mu.Unlock()
return weight
}
You could give it a try :)
@KujouRinka yes. The d.routedDispatch() is not thread safe. But if no goroutine here mutex will no need, or maybe just add a comment not thread safe. The key is why goroutine is used here? does here can not use goroutine?
Using goroutine is necessary. I think we can fix it by add mutex.
@KujouRinka Could you please submit a Pull Request?
@AkinoKaede Sure! see #2678.
This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days
What version of V2Ray are you using?
v2ray version V2Ray 5.4.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.20.2 linux/amd64) A unified platform for anti-censorship
What's your scenario of using V2Ray?
What problems have you encountered?
What's your expectation?
Please attach your configuration here
Server configuration:
Client configuration:
Please attach error logs here
Server error log:
Client error log:
Please attach access log here
Other configurations (such as Nginx) and logs here
If V2Ray cannot start up, please attach output from
--test
commandIf V2Ray service is abnormal, please attach journal log here