fix: tenta múltiplos hostnames para conectar ao Kernel

Tenta 127.0.0.1 e localhost para conectar ao Registry do Kernel.
Adiciona logs detalhados para debug.
This commit is contained in:
Jonas Pacheco 2026-04-08 12:17:35 -03:00
parent 524a049d03
commit da371af0e0
1 changed files with 20 additions and 5 deletions

View File

@ -26,15 +26,30 @@ async function fetchRegistryServicesWithRetry(maxRetries = 3, delay = 500): Prom
return null; return null;
} }
// Tenta múltiplos hostnames (127.0.0.1, localhost) para conectar ao Kernel
async function fetchRegistryServicesOnce(): Promise<any[] | null> { async function fetchRegistryServicesOnce(): Promise<any[] | null> {
const hostnames = ['127.0.0.1', 'localhost'];
for (const hostname of hostnames) {
const result = await tryConnectToRegistry(hostname);
if (result !== null) {
return result;
}
}
return null;
}
function tryConnectToRegistry(hostname: string): Promise<any[] | null> {
return new Promise((resolve) => { return new Promise((resolve) => {
const options = { const options = {
hostname: 'localhost', hostname,
port: 5001, port: 5001,
path: '/api/registry/services', path: '/api/registry/services',
method: 'GET', method: 'GET',
timeout: 3000, timeout: 3000,
}; };
console.log(`[Engine Room] Tentando conectar em ${hostname}:5001...`);
const req = http.request(options, (res) => { const req = http.request(options, (res) => {
let data = ''; let data = '';
@ -47,22 +62,22 @@ async function fetchRegistryServicesOnce(): Promise<any[] | null> {
try { try {
const json = JSON.parse(data); const json = JSON.parse(data);
const services = json.success && Array.isArray(json.data?.services) ? json.data.services : null; const services = json.success && Array.isArray(json.data?.services) ? json.data.services : null;
console.log(`[Engine Room] Registry retornou ${services?.length || 0} serviços`); console.log(`[Engine Room] Registry retornou ${services?.length || 0} serviços via ${hostname}`);
resolve(services); resolve(services);
} catch (e) { } catch (e) {
console.error('[Engine Room] Erro ao parsear resposta:', e); console.error(`[Engine Room] Erro ao parsear resposta de ${hostname}:`, e);
resolve(null); resolve(null);
} }
}); });
}); });
req.on('error', (error) => { req.on('error', (error) => {
console.error('[Engine Room] Erro ao consultar Registry:', error.message); console.error(`[Engine Room] Erro ao consultar Registry em ${hostname}:`, error.message);
resolve(null); resolve(null);
}); });
req.on('timeout', () => { req.on('timeout', () => {
console.error('[Engine Room] Timeout ao consultar Registry'); console.error(`[Engine Room] Timeout ao consultar Registry em ${hostname}`);
req.destroy(); req.destroy();
resolve(null); resolve(null);
}); });