logger: retry transient Slack webhook failures#4957
Conversation
|
|
||
| export function isRetryableSlackPostError(error: unknown): boolean { | ||
| const status = getErrorStatus(error); | ||
| return status !== undefined && SLACK_RETRYABLE_STATUS_CODES.has(status); |
There was a problem hiding this comment.
isRetryableSlackPostError only returns true when the error carries an HTTP status in the retryable set. Requests that fail without a response — timeouts, ECONNRESET, DNS failures — have status === undefined, so they are not retried and surface as a TransportError on the first attempt. Since connection-level failures are among the most common transient Slack delivery issues (and the PR title targets transient failures broadly), consider retrying those too, or documenting that only status-coded failures are in scope.
| export const SLACK_MAX_RETRY_DELAY_SECONDS = 5; | ||
|
|
||
| const SLACK_DEFAULT_RETRY_DELAY_SECONDS = 1; | ||
| const SLACK_RETRYABLE_STATUS_CODES = new Set([429, 500, 502, 503, 504]); |
There was a problem hiding this comment.
Retrying 5xx responses can lead to duplicate Slack messages: a 500/502/503/504 from an intermediary can occur after Slack already accepted the payload, and the retry re-posts the same chunk. Low impact for monitoring alerts, but worth noting since webhook posts aren't idempotent (429 is safe here since it's rejected, not delivered).
What Changed
packages/logger/src/logger/SlackTransport.ts.429responses and common transient5xxstatuses before surfacing aTransportError.Retry-Afterheaders when present and caps the wait at 5 seconds to avoid long logger stalls.Retry-Aftercapping.Why
429to a normal monitor notification.TransportError, which can be routed into PagerDuty whenlogTransportErrorsis enabled.Impact
TransportErrorto the existing transport-error path.High risk Sections to review with detail
postWithRetryinSlackTransport.ts: retry count, retryable status list, and delay cap are the main behavior changes.getSlackPostRetryDelaySeconds: validates both numeric and date-formRetry-Afterheaders while bounding delay time.Validation
git diff --checkandgit diff --cached --checksuccessfully.packages/logger/test/logger/SlackTransport.retries.jscovering the intended retry behavior.Docs