Skip to content

Commit f8eb36a

Browse files
committed
fix(data-drains): drain retryable response bodies in datadog/gcs loops
Mirrors the bigquery 401 fix. Without consuming the body before sleeping, undici can't return the socket to the keep-alive pool, so each retry leaks a TCP connection instead of reusing it.
1 parent 2e443f6 commit f8eb36a

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

apps/sim/lib/data-drains/destinations/datadog.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ async function postWithRetries(input: PostInput): Promise<Response> {
179179
}
180180
lastError = new Error(`Datadog responded with HTTP ${response.status}`)
181181
retryAfterMs = parseRetryAfter(response.headers.get('retry-after'))
182+
/** Drain the retryable response body so undici can return the socket to the keep-alive pool. */
183+
await response.text().catch(() => '')
182184
}
183185
if (attempt < MAX_ATTEMPTS) {
184186
await sleepUntilAborted(backoffWithJitter(attempt, retryAfterMs), input.signal)

apps/sim/lib/data-drains/destinations/gcs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ async function fetchWithRetry(input: RetryRequestInput): Promise<void> {
176176
}
177177
lastError = new Error(`GCS ${input.action} responded with HTTP ${response.status}`)
178178
const retryAfterMs = parseRetryAfter(response.headers.get('retry-after'))
179+
/** Drain the retryable response body so undici can return the socket to the keep-alive pool. */
180+
await response.text().catch(() => '')
179181
await sleepUntilAborted(backoffWithJitter(attempt, retryAfterMs), input.signal)
180182
}
181183
throw lastError instanceof Error

0 commit comments

Comments
 (0)