Trying to get to the bottom of this problem. I’ve got a lambda function that is just supposed to fire off a fetch request to an arbitrary invalid URL from an SQS record. Occasionally the ‘fetch’ will hang for about ten seconds, even though the code is demanding that it cut it off at one second. Most of the time though it works as intended. Attached:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = void 0;
require("dd-trace/init"); //Needs to come before any instrumented code
const handler = async (event) => {
const failures = [];
for (const r of event.Records) {
let webhookMessage;
try {
webhookMessage = JSON.parse(r.body);
}
catch (e) {
console.log("Error in parsing body", r);
}
if (!webhookMessage) {
failures.push({
itemIdentifier: r.messageId,
});
continue;
}
try {
console.time("fetch_url");
console.log("Fetching URL: ", webhookMessage.configuration.url);
const res = await fetch(webhookMessage.configuration.url, {
method: "POST",
body: JSON.stringify(webhookMessage.data),
signal: AbortSignal.timeout(1000),
});
if (!res.ok) {
console.log("URL fetch failed: ", res.status);
failures.push({
itemIdentifier: r.messageId,
});
}
}
catch (e) {
console.log("URL fetch failed without response: ", e);
failures.push({
itemIdentifier: r.messageId,
});
}
console.timeEnd("fetch_url");
}
return {
batchItemFailures: failures,
};
};
exports.handler = handler;
Since this is a lambda I’ve got limited insights, but the logs show (cleaned up)…
Fetching URL: http://174.129.145.242/
URL fetch failed without response: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11730:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async handler (/var/task/index.js:30:25) {
cause: ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (node:internal/deps/undici/undici:6869:28)
at node:internal/deps/undici/undici:6825:50
at Immediate._onImmediate (node:internal/deps/undici/undici:6857:13)
at process.processImmediate (node:internal/timers:476:21)
at process.callbackTrampoline (node:internal/async_hooks:128:17) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
fetch_url: 10.262s //<- this is the amount of time the console.time -> console.timeEnd took, in case it wasn't obvious
I thought this might have had something to do with the datadog integration, but I just verified it was happening before we added that – just so happened that the integration helped show that the hang was happening on the fetch
, which led to additional commenting and such.