add semaphore on grpc

This commit is contained in:
Pascal Fischer
2025-05-07 18:06:10 +02:00
parent b43def9164
commit 7b8929e8ba
2 changed files with 10 additions and 1 deletions

View File

@@ -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)

View File

@@ -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()