Refactor VPN config creation logic to improve node status handling
CI / Backend (build + test) (push) Successful in 1m19s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s

- Removed the dependency on `Node.Status` for VPN config creation, addressing potential false negatives due to cached health-check data.
- Updated documentation to clarify that `Node.Status` is a diagnostic indicator and not a gate for config creation, ensuring accurate understanding of node availability checks.
- Enhanced comments in the code to explain the rationale behind the changes, improving maintainability and clarity for future developers.
This commit is contained in:
Leonid Pershin
2026-07-15 15:53:47 +03:00
parent f14daa3df1
commit d30c958dc4
2 changed files with 15 additions and 6 deletions
@@ -4,7 +4,6 @@ using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Common.Messaging;
using PnvPanel.Application.Common.Models;
using PnvPanel.Domain.Configs;
using PnvPanel.Domain.Nodes;
namespace PnvPanel.Application.Configs.Create;
@@ -40,7 +39,11 @@ public sealed class CreateVpnConfigCommandHandler(
var node = await dbContext
.Nodes.AsNoTracking()
.FirstOrDefaultAsync(n => n.Id == inbound.NodeId, cancellationToken);
if (node is null || !node.IsEnabled || node.Status == NodeStatus.Offline)
// Node.Status — это кэш периодического health-check'а (раз в 2 минуты), а не проверка
// в реальном времени: блокировать по нему создание конфига значит ловить ложные отказы на
// временных сетевых сбоях пробника. Реальную недоступность ловит AddClientAsync ниже —
// тот бьёт в панель прямо сейчас и возвращает честную ошибку с компенсацией.
if (node is null || !node.IsEnabled)
return Result.Failure<VpnConfigDto>(ConfigErrors.NodeDisabled);
var config = VpnConfig.Create(userId, inbound.Id, inbound.Protocol, command.Label);