Fixed sync error
testing/ogcore-api/pipeline/head There was a failure building this commit Details

pull/102/head
Manuel Aranda Rosales 2026-04-29 12:40:38 +02:00
parent 40be572cfc
commit f6e4234150
3 changed files with 53 additions and 22 deletions

View File

@ -63,6 +63,26 @@ class AgentSessionController extends AbstractController
$this->entityManager->persist($client);
$this->entityManager->flush();
// Notify UDS the machine is now running the session OS and ready for connection.
$remotePC = $client->getRemotePC();
if ($remotePC && $remotePC->isReservedActive() && $remotePC->getUrlLogin()) {
try {
$this->httpClient->request('POST', $remotePC->getUrlLogin(), [
'verify_host' => false,
'json' => [
'ip' => $data['ip'],
'ostype' => $data['ostype'],
'osversion' => $data['osversion'],
'agent_version' => $data['agent_version'],
],
'headers' => ['Content-Type' => 'application/json'],
]);
$this->logger->info('RemotePC: urlLogin called on agent start', ['ip' => $data['ip']]);
} catch (\Throwable $e) {
$this->logger->warning('RemotePC: urlLogin on agent start failed', ['ip' => $data['ip'], 'error' => $e->getMessage()]);
}
}
$this->logger->info('Client started', [
'mac' => $data['mac'],
'ip' => $data['ip'],

View File

@ -55,6 +55,7 @@ class StatusController extends AbstractController
protected readonly CreatePartitionService $createPartitionService,
protected readonly LoggerInterface $logger,
protected readonly CreateService $createService,
protected readonly HttpClientInterface $httpClient,
)
{
}
@ -359,24 +360,33 @@ class StatusController extends AbstractController
if (isset($data['nfn']) && $data['nfn'] === self::INICIAR_SESION) {
$clientIp = $data['iph'] ?? $request->getClientIp();
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]);
if ($client && isset($data['res']) && (int) $data['res'] !== 1) {
// IniciarSesion failed on the agent side; re-queue the login trace
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy([
'client' => $client,
'command' => CommandTypes::LOGIN,
'status' => TraceStatus::PENDING,
]);
if (!$trace) {
$this->logger->warning('RESPUESTA_IniciarSesion: failure, no pending trace to retry', [
if ($client) {
$res = isset($data['res']) ? (int) $data['res'] : null;
if ($res === 1) {
// IniciarSesion acknowledged by OGLive agent: machine is booting to Windows.
// Call urlLogin early so UDS doesn't timeout (~21s) waiting for the real loggedin.
// agentLoggedIn will call urlLogin again once the user actually logs into Windows.
$remotePC = $client->getRemotePC();
if ($remotePC && $remotePC->isReservedActive() && $remotePC->getUrlLogin()) {
try {
$this->httpClient->request('POST', $remotePC->getUrlLogin(), [
'verify_host' => false,
'json' => ['ip' => $clientIp],
'headers' => ['Content-Type' => 'application/json'],
]);
$this->logger->info('RemotePC: early urlLogin called after IniciarSesion ack', ['ip' => $clientIp]);
} catch (\Throwable $e) {
$this->logger->warning('RemotePC: early urlLogin failed', ['ip' => $clientIp, 'error' => $e->getMessage()]);
}
}
} else {
// IniciarSesion failed — log it; the PENDING trace will retry on next cron run
$this->logger->warning('RESPUESTA_IniciarSesion: agent reported failure', [
'ip' => $clientIp,
'job_id' => $data['job_id'] ?? null,
'res' => $data['res'] ?? null,
]);
} else {
$this->logger->warning('RESPUESTA_IniciarSesion: failure, trace kept pending for retry', [
'ip' => $clientIp,
'trace_id' => $trace->getId(),
'res' => $data['res'] ?? null,
'res' => $res,
]);
}
}

View File

@ -3,7 +3,6 @@
namespace App\EventListener;
use App\Entity\Client;
use App\Model\ClientStatus;
use App\Service\UDS\UDSClient;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PostFlushEventArgs;
@ -38,11 +37,13 @@ class UdsSyncOnClientStatusListener
return;
}
// INITIALIZING is a transient state set during the RemotePC reserve flow.
// Syncing with UDS at this point sends max_srvs=0/visible=false, which causes
// UDS to cancel the active reservation with an unreserve call after ~20 seconds.
[, $newStatus] = $changeSet['status'];
if ($newStatus === ClientStatus::INITIALIZING) {
// Don't sync while the machine has an active RemotePC reservation.
// Any status change during a reservation (INITIALIZING, OG_LIVE via InclusionCliente,
// WINDOWS after boot, etc.) would compute max_srvs=0/visible=false and cause UDS
// to cancel the active session with an unreserve call.
// The sync will fire again after unreserve clears the reservation (reservedUntil=null).
$remotePC = $entity->getRemotePC();
if ($remotePC && $remotePC->isReservedActive()) {
return;
}