mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-07 03:52:34 +02:00
fix(route): add mutex lock for load balancer updates to prevent race conditions
This commit is contained in:
parent
bd0fe36c53
commit
09c244ef3c
1 changed files with 7 additions and 0 deletions
|
@ -3,6 +3,7 @@ package route
|
|||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/yusing/go-proxy/agent/pkg/agent"
|
||||
"github.com/yusing/go-proxy/agent/pkg/agentproxy"
|
||||
|
@ -156,12 +157,17 @@ func (r *ReveseProxyRoute) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
r.handler.ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
var lbLock sync.Mutex
|
||||
|
||||
func (r *ReveseProxyRoute) addToLoadBalancer(parent task.Parent) {
|
||||
var lb *loadbalancer.LoadBalancer
|
||||
cfg := r.LoadBalance
|
||||
lbLock.Lock()
|
||||
|
||||
l, ok := routes.HTTP.Get(cfg.Link)
|
||||
var linked *ReveseProxyRoute
|
||||
if ok {
|
||||
lbLock.Unlock()
|
||||
linked = l.(*ReveseProxyRoute)
|
||||
lb = linked.loadBalancer
|
||||
lb.UpdateConfigIfNeeded(cfg)
|
||||
|
@ -186,6 +192,7 @@ func (r *ReveseProxyRoute) addToLoadBalancer(parent task.Parent) {
|
|||
routes.HTTP.DelKey(cfg.Link)
|
||||
routes.All.DelKey(cfg.Link)
|
||||
})
|
||||
lbLock.Unlock()
|
||||
}
|
||||
r.loadBalancer = lb
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue