mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
[management] fix some concurrency potential issues (#5584)
This commit is contained in:
@@ -63,11 +63,20 @@ func (ac *AccountRequestBuffer) GetAccountWithBackpressure(ctx context.Context,
|
|||||||
|
|
||||||
log.WithContext(ctx).Tracef("requesting account %s with backpressure", accountID)
|
log.WithContext(ctx).Tracef("requesting account %s with backpressure", accountID)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
ac.getAccountRequestCh <- req
|
|
||||||
|
|
||||||
result := <-req.ResultChan
|
select {
|
||||||
log.WithContext(ctx).Tracef("got account with backpressure after %s", time.Since(startTime))
|
case <-ctx.Done():
|
||||||
return result.Account, result.Err
|
return nil, ctx.Err()
|
||||||
|
case ac.getAccountRequestCh <- req:
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ctx.Err()
|
||||||
|
case result := <-req.ResultChan:
|
||||||
|
log.WithContext(ctx).Tracef("got account with backpressure after %s", time.Since(startTime))
|
||||||
|
return result.Account, result.Err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AccountRequestBuffer) processGetAccountBatch(ctx context.Context, accountID string) {
|
func (ac *AccountRequestBuffer) processGetAccountBatch(ctx context.Context, accountID string) {
|
||||||
|
|||||||
@@ -51,19 +51,28 @@ func GetList() []string {
|
|||||||
// This can be used to bypass authz/authn middlewares for certain paths, such as webhooks that implement their own authentication.
|
// This can be used to bypass authz/authn middlewares for certain paths, such as webhooks that implement their own authentication.
|
||||||
func ShouldBypass(requestPath string, h http.Handler, w http.ResponseWriter, r *http.Request) bool {
|
func ShouldBypass(requestPath string, h http.Handler, w http.ResponseWriter, r *http.Request) bool {
|
||||||
byPassMutex.RLock()
|
byPassMutex.RLock()
|
||||||
defer byPassMutex.RUnlock()
|
var matched bool
|
||||||
|
|
||||||
for bypassPath := range bypassPaths {
|
for bypassPath := range bypassPaths {
|
||||||
matched, err := path.Match(bypassPath, requestPath)
|
m, err := path.Match(bypassPath, requestPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithContext(r.Context()).Errorf("Error matching path %s with %s from %s: %v", bypassPath, requestPath, GetList(), err)
|
list := make([]string, 0, len(bypassPaths))
|
||||||
|
for k := range bypassPaths {
|
||||||
|
list = append(list, k)
|
||||||
|
}
|
||||||
|
log.WithContext(r.Context()).Errorf("Error matching path %s with %s from %v: %v", bypassPath, requestPath, list, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if matched {
|
if m {
|
||||||
h.ServeHTTP(w, r)
|
matched = true
|
||||||
return true
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
byPassMutex.RUnlock()
|
||||||
|
|
||||||
|
if matched {
|
||||||
|
h.ServeHTTP(w, r)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ func NewChannel() *Channel {
|
|||||||
return jc
|
return jc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jc *Channel) AddEvent(ctx context.Context, responseWait time.Duration, event *Event) error {
|
func (jc *Channel) AddEvent(ctx context.Context, responseWait time.Duration, event *Event) (err error) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err = ErrJobChannelClosed
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|||||||
@@ -152,6 +152,8 @@ func (n *Network) CurrentSerial() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Network) Copy() *Network {
|
func (n *Network) Copy() *Network {
|
||||||
|
n.Mu.Lock()
|
||||||
|
defer n.Mu.Unlock()
|
||||||
return &Network{
|
return &Network{
|
||||||
Identifier: n.Identifier,
|
Identifier: n.Identifier,
|
||||||
Net: n.Net,
|
Net: n.Net,
|
||||||
|
|||||||
Reference in New Issue
Block a user