Fix failed deliveries
Use this guide when a receiver missed webhooks after a failed attempt. A retry sends the same delivery again, with the same webhook-id. To send events for which EventWolf created no delivery, such as those accepted while a subscription was paused, replay them. Deliveries explains attempts, retries, and statuses.
Before you start
- The
apihelper, from Platform quickstart. - A
devsecret key,key, for a project that adopted EventWolf, from Create a project and issue a key.
This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.
1. Find the failing deliveries
A delivery waiting for a retry is pending. A delivery that ran out of retries, or whose receiver answered 410, is failed. List both webhook statuses and keep the deliveries whose attempts have started:
const failing = [];
for (const status of ['failed', 'pending']) {
const { deliveries } = await api(
'GET',
`/v1/events/deliveries?kind=webhook&status=${status}&limit=200`,
key,
);
failing.push(...deliveries.filter((delivery) => delivery.attempts > 0));
}
console.log(failing.length, failing[0].status); // 1 pending
attempts counts every attempt so far, EventWolf’s own retries included. Agentpost’s starting schedule retries 5 seconds after the first failure.
An endpoint’s test is a delivery too, with no subscriptionId. Add endpointId or subscriptionId to narrow the results. While an answer has next, send it as after with the same filters for the next page.
To list deliveries for one event, send its sequence as eventSequence. Get the sequence from the publish result or look up the event by source and id.
2. Read why it failed
Get the delivery with its attempts. The last recorded attempt holds the receiver’s answer, or why there was none. A delivery’s attempts counts an attempt from when it starts, and the attempt’s record appears when it ends. Wait until the delivery has a record for each attempt before you read the last one.
let { delivery, attempts } = await api(
'GET',
`/v1/events/deliveries/${failing[0].id}`,
key,
);
for (
let wait = 0;
wait < 30 && attempts.length < delivery.attempts;
wait += 1
) {
await new Promise((resolve) => setTimeout(resolve, 1000));
({ delivery, attempts } = await api(
'GET',
`/v1/events/deliveries/${failing[0].id}`,
key,
));
}
const last = attempts.at(-1);
console.log(
last.response?.status ?? last.error?.code,
last.response?.bodyExcerpt,
);
// 503 upstream unavailable
delivery.nextAttemptAt is when EventWolf tries again by itself.
3. Fix the cause
Find what the last attempt shows, and fix it before you send the delivery again:
| The last attempt shows | What to fix |
|---|---|
response. 5xx |
The receiver failed. response.bodyExcerpt holds the first 2 KB of its answer; fix the receiver. |
response. 429 or 503 |
The receiver was busy. EventWolf already waits as its Retry-After asks, up to a day, until nextAttemptAt, so a retry may not be needed. |
response. 401 or 403 |
The receiver refused the request: check that it verifies with the endpoint’s current secret, and the endpoint’s static headers. |
response. 404 or 405 |
The URL is wrong. Update the endpoint with the right url. |
response. 410 |
Fix the receiver or its URL and enable the endpoint. Retry the failed delivery, or recover failed and skipped deliveries with since set to when the earliest of them was created. |
error. dns, connection, tls |
EventWolf couldn’t reach the receiver: check the URL’s hostname, that the server is up, and its certificate. |
error. timeout |
The receiver took longer than the config’s delivery.timeout, "15s" in Agentpost’s starting config. Answer 2xx first, then do slow work. |
error. redirect |
The receiver answered 3xx, which isn’t followed. Update the endpoint with the final URL. |
error. ssrf_blocked |
The URL resolves to a private or reserved address. Use a public address. |
4. Retry the delivery
Once the receiver works, retry the delivery to put it back in the queue for an immediate attempt. A scheduled retry can increase attempts while you look. A retry answers conflict while an attempt is in progress or once the delivery has succeeded:
const retried = await api(
'POST',
`/v1/events/deliveries/${delivery.id}/retry`,
key,
);
console.log(retried.delivery.status); // pending
A delivery that succeeded answers conflict: replay its event to send it again. When many deliveries of one endpoint failed, such as during an outage, recover them in one request instead.
Check it worked
Read the delivery until it leaves pending:
let after = retried.delivery;
for (let wait = 0; wait < 30 && after.status === 'pending'; wait += 1) {
await new Promise((resolve) => setTimeout(resolve, 1000));
({ delivery: after } = await api(
'GET',
`/v1/events/deliveries/${delivery.id}`,
key,
));
}
console.log(after.status); // succeeded
If the retry fails, go back to step 2. A delivery still pending after this check can be waiting for its attempt or its next retry. Read its last recorded attempt and nextAttemptAt.