mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 05:11:17 +08:00
Fixed: race condition in update config
This commit is contained in:
parent
2897ce916a
commit
a74856dbf3
@ -24,6 +24,7 @@ type Tunnel struct {
|
||||
proxys map[string]C.Proxy
|
||||
observable *observable.Observable
|
||||
logCh chan interface{}
|
||||
configLock *sync.RWMutex
|
||||
}
|
||||
|
||||
func (t *Tunnel) Add(req C.ServerAdapter) {
|
||||
@ -31,6 +32,9 @@ func (t *Tunnel) Add(req C.ServerAdapter) {
|
||||
}
|
||||
|
||||
func (t *Tunnel) UpdateConfig() (err error) {
|
||||
t.configLock.Lock()
|
||||
defer t.configLock.Unlock()
|
||||
|
||||
cfg, err := C.GetConfig()
|
||||
if err != nil {
|
||||
return
|
||||
@ -113,6 +117,9 @@ func (t *Tunnel) handleConn(localConn C.ServerAdapter) {
|
||||
}
|
||||
|
||||
func (t *Tunnel) match(addr *C.Addr) C.Proxy {
|
||||
t.configLock.RLock()
|
||||
defer t.configLock.RUnlock()
|
||||
|
||||
for _, rule := range t.rules {
|
||||
if rule.IsMatch(addr) {
|
||||
a, ok := t.proxys[rule.Adapter()]
|
||||
@ -134,6 +141,7 @@ func newTunnel() *Tunnel {
|
||||
proxys: make(map[string]C.Proxy),
|
||||
observable: observable.NewObservable(logCh),
|
||||
logCh: logCh,
|
||||
configLock: &sync.RWMutex{},
|
||||
}
|
||||
go tunnel.process()
|
||||
go tunnel.subscribeLogs()
|
||||
|
Loading…
Reference in New Issue
Block a user