Don't repeatedly call isImdsEndpoint

This commit is contained in:
Sander Declerck 2025-12-05 12:12:22 +01:00
parent 57a0e88fa4
commit e421414b8a
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View file

@ -5,7 +5,7 @@
const imdsEndpoints = [
"metadata.google.internal",
"metadata.goog",
"169.254.169.254",
"169.254.169.254", // AWS, Azure, Oracle Cloud, GCP
];
export function isImdsEndpoint(/** @type {string} */ host) {

View file

@ -76,13 +76,17 @@ function tunnelRequestToDestination(req, clientSocket, head) {
serverSocket.on("timeout", () => {
timedoutEndpoints.push(hostname);
// Suppress error logging for IMDS endpoints - timeouts are expected when not in cloud
if (isImdsEndpoint(hostname)) {
if (isImds) {
ui.writeVerbose(
`Safe-chain: connect to ${hostname}:${port || 443} timed out after ${connectTimeout}ms`
`Safe-chain: connect to ${hostname}:${
port || 443
} timed out after ${connectTimeout}ms`
);
} else {
ui.writeError(
`Safe-chain: connect to ${hostname}:${port || 443} timed out after ${connectTimeout}ms`
`Safe-chain: connect to ${hostname}:${
port || 443
} timed out after ${connectTimeout}ms`
);
}
serverSocket.destroy(); // Clean up socket to prevent event loop hanging
@ -98,7 +102,7 @@ function tunnelRequestToDestination(req, clientSocket, head) {
});
serverSocket.on("error", (err) => {
if (isImdsEndpoint(hostname)) {
if (isImds) {
ui.writeVerbose(
`Safe-chain: error connecting to ${hostname}:${port} - ${err.message}`
);