mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-19 23:11:29 +02:00
add semaphore on grpc
This commit is contained in:
@@ -444,6 +444,16 @@ func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*p
|
||||
//nolint
|
||||
ctx = context.WithValue(ctx, nbContext.AccountIDKey, accountID)
|
||||
|
||||
err = TryAcquire(loginReq.GetPeerKeys().String())
|
||||
if err != nil {
|
||||
log.WithContext(ctx).Debugf("error while acquiring grpc semaphore for %s: %v", loginReq.GetPeerKeys().String(), err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
Release(loginReq.GetPeerKeys().String())
|
||||
}()
|
||||
|
||||
if loginReq.GetMeta() == nil {
|
||||
msg := status.Errorf(codes.FailedPrecondition,
|
||||
"peer system meta has to be provided to log in. Peer %s, remote addr %s", peerKey.String(), realIP)
|
||||
|
||||
@@ -463,7 +463,6 @@ func TryAcquire(key string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Release marks a worker key as free.
|
||||
func Release(key string) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user