Only timeout for imds endpoints

This commit is contained in:
Sander Declerck 2025-12-09 15:25:19 +01:00
parent cef2194427
commit afc68618c6
No known key found for this signature in database

View file

@ -3,7 +3,7 @@ import { ui } from "../environment/userInteraction.js";
import { isImdsEndpoint } from "./isImdsEndpoint.js";
/** @type {string[]} */
let timedoutEndpoints = [];
let timedoutImdsEndpoints = [];
/**
* @param {import("http").IncomingMessage} req
@ -43,7 +43,7 @@ function tunnelRequestToDestination(req, clientSocket, head) {
const { port, hostname } = new URL(`http://${req.url}`);
const isImds = isImdsEndpoint(hostname);
if (timedoutEndpoints.includes(hostname)) {
if (timedoutImdsEndpoints.includes(hostname)) {
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
if (isImds) {
ui.writeVerbose(
@ -74,9 +74,9 @@ function tunnelRequestToDestination(req, clientSocket, head) {
serverSocket.setTimeout(connectTimeout);
serverSocket.on("timeout", () => {
timedoutEndpoints.push(hostname);
// Suppress error logging for IMDS endpoints - timeouts are expected when not in cloud
if (isImds) {
timedoutImdsEndpoints.push(hostname);
ui.writeVerbose(
`Safe-chain: connect to ${hostname}:${
port || 443