Skip to content

Commit c8c7980

Browse files
fix(telegram): handle EADDRNOTAVAIL local socket exhaustion correctly [AI-assisted]
1 parent dba291e commit c8c7980

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

extensions/telegram/src/fetch.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,27 @@ describe("resolveTelegramFetch", () => {
11931193
expect(undiciFetch).toHaveBeenCalledTimes(1);
11941194
});
11951195

1196+
it("does not retry on EADDRNOTAVAIL local socket allocation failure", async () => {
1197+
const fetchError = buildFetchFallbackError("EADDRNOTAVAIL");
1198+
undiciFetch.mockRejectedValue(fetchError);
1199+
1200+
const resolved = resolveTelegramFetchOrThrow(undefined, {
1201+
network: {
1202+
autoSelectFamily: true,
1203+
},
1204+
});
1205+
1206+
await expect(resolved("https://api.telegram.org/botx/sendMessage")).rejects.toThrow(
1207+
"fetch failed",
1208+
);
1209+
1210+
expect(undiciFetch).toHaveBeenCalledTimes(1);
1211+
expectLoggerMessageContaining(
1212+
loggerWarn,
1213+
"telegram transport encountered local socket allocation failure (EADDRNOTAVAIL)",
1214+
);
1215+
});
1216+
11961217
it("retries sticky fallback when the local network is down during connect", async () => {
11971218
undiciFetch
11981219
.mockRejectedValueOnce(buildFetchFallbackError("ENETDOWN"))

extensions/telegram/src/fetch.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ function shouldUseTelegramTransportFallback(err: unknown): boolean {
473473
: "",
474474
codes: collectErrorCodes(err),
475475
};
476+
if (ctx.codes.has("EADDRNOTAVAIL") || ctx.message.includes("eaddrnotavail")) {
477+
log.warn(
478+
"telegram transport encountered local socket allocation failure (EADDRNOTAVAIL) — check ephemeral ports / mbuf zones / network extensions; remote IP rotation will not help",
479+
);
480+
return false;
481+
}
476482
const hasFetchFailedEnvelope = ctx.message.includes("fetch failed");
477483
const hasKnownNetworkCode = FALLBACK_RETRY_ERROR_CODES.some((code) => ctx.codes.has(code));
478484
return hasKnownNetworkCode || (hasFetchFailedEnvelope && ctx.codes.size === 0);

0 commit comments

Comments
 (0)