diff --git a/management/server/grpcserver.go b/management/server/grpcserver.go index d426f6f2f..329a58a91 100644 --- a/management/server/grpcserver.go +++ b/management/server/grpcserver.go @@ -469,6 +469,10 @@ func (s *GRPCServer) parseRequest(ctx context.Context, req *proto.EncryptedMessa // In case it isn't, the endpoint checks whether setup key is provided within the request and tries to register a peer. // In case of the successful registration login is also successful func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*proto.EncryptedMessage, error) { + if s.appMetrics != nil { + s.appMetrics.GRPCMetrics().CountLoginRequest() + } + limiterIface, ok := s.loginLimiterStore.Load(req.WgPubKey) if !ok { // Check global limiter before allowing a new peer limiter @@ -516,9 +520,7 @@ func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*p s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart)) } }() - if s.appMetrics != nil { - s.appMetrics.GRPCMetrics().CountLoginRequest() - } + realIP := getRealIP(ctx) log.WithContext(ctx).Debugf("Login request from peer [%s] [%s]", req.WgPubKey, realIP.String()) diff --git a/management/server/peer.go b/management/server/peer.go index ab8ab82fb..d93134637 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -475,6 +475,13 @@ func (am *DefaultAccountManager) AddPeer(ctx context.Context, setupKey, userID s return nil, nil, nil, status.Errorf(status.NotFound, "failed adding new peer: account not found") } + unlock := am.Store.AcquireWriteLockByUID(ctx, accountID) + defer func() { + if unlock != nil { + unlock() + } + }() + // This is a handling for the case when the same machine (with the same WireGuard pub key) tries to register twice. // Such case is possible when AddPeer function takes long time to finish after AcquireWriteLockByUID (e.g., database is slow) // and the peer disconnects with a timeout and tries to register again.