DEV Community

Vladimir Elchinov for Session Replay

Posted on

The Webhook That Never Arrived Leaves No Error Anywhere. GitHub Will Not Send It Again.

Yesterday GitHub had a critical incident: from 15:55 to 16:52 UTC its status page listed Git operations, Actions, Pages, Issues, pull requests, the API and webhooks as degraded, and named the cause as high database load. It was resolved within the hour.

If you run anything that listens to GitHub webhooks, the outage is over but its effect may not be. Somewhere there may be a deploy that never started, a CI status that never posted, a ticket that never moved. None of it produced an error on your side, because nothing arrived to fail.

GitHub does not retry

This is the line in GitHub's documentation that most integrations are built without knowing: "GitHub does not automatically redeliver failed webhook deliveries."

A delivery that failed is recorded as failed, and that is the end of it unless somebody acts. GitHub keeps the record and lets you redeliver it manually, through the repository's webhook settings or the REST API's "Redeliver a delivery" endpoints, but the docs limit that to "webhook deliveries that occurred in the past 3 days". For yesterday's incident, that window closes on Saturday afternoon.

You do not need an outage to lose one

The incident is the dramatic case. The everyday one is your own handler.

GitHub's best-practice guide says to respond within 10 seconds, and spells out what happens if you do not: GitHub "terminates the connection and considers the delivery a failure". So a handler that runs the build, calls three APIs and writes to a slow database before answering will, on a busy afternoon, lose deliveries with nobody noticing. GitHub's own advice is to answer immediately and do the work from a queue.

The cruel detail is that a timed-out handler often finishes the work anyway. GitHub has marked the delivery failed; your code completed it. Which matters the moment somebody does the right thing and redelivers it.

Make redelivery safe before you need it

Every delivery carries an X-GitHub-Delivery header, which the docs describe as "a globally unique identifier (GUID) to identify the event". And, crucially: "If you request a redelivery, the X-GitHub-Delivery header will be the same as in the original delivery."

That makes deduplication a one-line rule:

app.post('/github', async (req, res) => {
  const id = req.get('X-GitHub-Delivery')
  if (await seen.has(id)) return res.sendStatus(200)  // already handled, possibly after a timeout
  await queue.add({ id, event: req.get('X-GitHub-Event'), body: req.body })
  await seen.add(id)
  res.sendStatus(202)                                  // answer now, work later
})
Enter fullscreen mode Exit fullscreen mode

Answer fast, queue the work, record the ID. Then a redelivery of something you already processed is a no-op, and a redelivery of something you never saw does the job it was meant to do.

And look for the gap on purpose

The deeper problem is the one that makes this kind of failure expensive: an event that never arrived looks exactly like an event that never happened. Your logs are empty in both cases. Your error tracker is quiet in both cases. The difference only appears when a person notices that the deploy did not go out, and by then the three-day window may have closed.

So check for it rather than wait for the report. GitHub's REST API has "List deliveries" endpoints for repository, organisation and app webhooks, and each delivery records whether it succeeded. A small scheduled job that lists the last day's deliveries and redelivers the failures turns "it just didn't happen" into something that fixes itself, and turns an incident like yesterday's into a non-event.

The general version

Most of the bugs worth fearing make noise. These do not. A missing event, a skipped job, a message that was never sent: each one leaves a silence that is indistinguishable from nothing having been needed. If your system reacts to things other systems tell it, decide now how you would know that one of them stopped telling you.

GitHub's incident page for 25 November, and the documentation quoted above, are the sources here; how other webhook providers retry varies, so check yours rather than assuming it behaves like either.

Top comments (0)