# Gitea webhooks in production: duplicates, retries and timeouts

Agent skill: `npx skills add hookdeck/webhook-skills --skill gitea-webhooks` ([details](https://hookdeck.com/webhooks/gitea/skill))

This guide covers the problems Gitea webhooks cause in production and how to handle each one. It applies to Gitea's generic webhook type. The Slack, Discord, Teams and other integrations send service-specific bodies and aren't covered here. What Gitea sends and how to set it up is on the [Gitea webhooks](/webhooks/gitea) overview, every event type is on [Gitea webhook events](/webhooks/gitea/events), and signature verification code is on [Verify Gitea webhooks](/webhooks/gitea/verify).

## At a glance

| Problem | What to do | With Event Gateway |
| --- | --- | --- |
| [Timeouts](#timeouts) | Return a 2xx inside the 5 second default; process in a background job | Accepts the delivery at once, then queues it for your service |
| [Retries](#retries) | Redeliver failures by hand before the instance cleans them up | Stores each delivery and retries to your service on your schedule |
| [Duplicates](#duplicates) | Make handlers idempotent; key on what changed, not `X-Gitea-Delivery` | Drops repeats based on the fields you choose |
| [Choosing events](#choosing-events) | Route on `X-Gitea-Event-Type`; subscribe narrowly | Filters and routes on headers and body |
| [Testing](#testing) | Use Test Delivery, and forward to localhost with a CLI | Forwards to localhost and replays past events |
| [Other limits](#other-limits) | Use `POST` with `application/json`; check the instance's egress settings | Verifies the signature on `POST` + `application/json` deliveries |

## Gitea webhook timeouts and slow handlers {#timeouts}

Return a 2xx inside the instance's delivery timeout, which is 5 seconds by default, then do the work in a background job.

**Why it happens:** The timeout is the `DELIVER_TIMEOUT` setting in the instance's `[webhook]` section, and only a 2xx counts as success. A handler that writes to a database or calls other services before responding can run past it, and Gitea's docs describe no automatic retry to recover the delivery.

**Fix it in your handler:**

1. Verify the signature, enqueue the event and respond straight away. See [why to process webhooks asynchronously](/webhooks/guides/why-implement-asynchronous-processing-webhooks).
2. Keep the request path free of calls to other services.
3. If you run the instance, you can raise `DELIVER_TIMEOUT`, though a faster receiver is the better fix.

**With Event Gateway:** Hookdeck accepts each Gitea delivery immediately, then queues it and delivers it to your service at a rate it can handle. Your handler can take as long as it needs without failing a Gitea delivery.

## Gitea webhook retries and redelivery {#retries}

Gitea's docs describe no automatic retries. A failed delivery stays failed until someone clicks Redelivery on the webhook page.

**Why it happens:** [Gitea's sender](https://github.com/go-gitea/gitea/blob/main/services/webhook/deliver.go) makes one attempt per delivery and records the result. By default, a cleanup job deletes delivered records older than 168 hours, and an administrator can switch it to keeping a set number per webhook, 10 by default.

**Fix it in your handler:**

1. Keep the endpoint up during deploys, because a delivery that fails then won't come back on its own.
2. After any downtime, open Recent Deliveries on each webhook and use Redelivery for the failures while the instance still holds the records.

**With Event Gateway:** Hookdeck answers Gitea immediately and stores each delivery, then [retries](/docs/retries) towards your service on your schedule. An outage on your side no longer means a manual redelivery session.

## Duplicate Gitea webhooks {#duplicates}

Redelivery replays an earlier delivery, so the same change can reach your handler twice. Make handlers idempotent, and key on what changed.

**Why it happens:** `X-Gitea-Delivery` is a unique UUID for each attempt, so a redelivery has a new value and a record of processed IDs won't catch it. Gitea's docs don't say whether an event can be delivered twice without a redelivery.

**Fix it in your handler:**

1. Build an idempotency key from the object and its state, such as a push's `after` SHA, or a pull request's `number` with its `action`. See our [guide to webhook idempotency](/webhooks/guides/implement-webhook-idempotency).
2. Store processed keys with a unique constraint.
3. Wrap the side effect and the key record in one transaction.

**With Event Gateway:** Hookdeck's [deduplication](/docs/deduplication) can drop repeats based on the fields you choose.

## Choosing and routing Gitea events {#choosing-events}

Route on `X-Gitea-Event-Type`, then on the body's `action`, and subscribe only to the events you process.

**Why it happens:** `X-Gitea-Event` and `X-GitHub-Event` carry a group, not the exact trigger, so an issue assignment arrives with `X-Gitea-Event: issues` and `X-Gitea-Event-Type: issue_assign`. A handler on the group treats a label change as just another issue event. [The group names](https://github.com/go-gitea/gitea/blob/main/modules/webhook/type.go) can also mislead: a `pull_request_comment` trigger arrives under the group `issue_comment`, while the group `pull_request_comment` means the trigger `pull_request_review_comment`.

The branch filter has a limit too. It applies only to events with a git ref, such as `create`, `delete` and `push`, so a webhook filtered to `main` still sends issue and release events.

**Fix it in your handler:**

1. Switch on `X-Gitea-Event-Type`, then on `action` where the event has one. `create`, `delete`, `fork`, `push` and `status` have none.
2. Under Trigger On, prefer a custom selection to All Events. Selecting `pull_request_review` subscribes you to the approved, rejected and comment review events, and it never arrives under that name.
3. Add a branch filter for ref events, and check `ref` in your handler if the filter is broad.

**With Event Gateway:** Hookdeck [filters](/docs/filters) match on headers as well as the body, so a filter on the event type header or `ref` can drop what you don't need, and each event type can go to its own destination.

## Testing and debugging Gitea webhooks {#testing}

Start with Test Delivery on the webhook page, then forward real events to your local server with a CLI.

**Why it's awkward:** Test Delivery only sends a synthetic `push`, using a generated fake commit if the repository has none, so other events need real activity. Pointing a webhook straight at a machine on your network can also fail, because in the default `EGRESS_MODE` an instance needs private addresses listed in `ALLOWED_HOST_LIST`.

**What to do:**

1. Use Test Delivery to check the URL, secret and content type.
2. Read Recent Deliveries for the request and response of each attempt, and use Redelivery to replay a real event to your handler.
3. Forward to localhost through a public URL, so the instance doesn't need a change to its allow list.

**With Event Gateway:** The [Hookdeck CLI](/docs/cli) receives webhooks on your machine without a public server, and you can replay past events with one click.

## Other Gitea webhook limits {#other-limits}

**Form-encoded and GET deliveries.** Use `POST` with `application/json`. Gitea signs the JSON payload for every delivery, while a form delivery's body is `payload=<url-encoded JSON>` and a `GET` puts the payload in the query string, so a check of the raw body fails on both. Gitea's docs say the raw body is signed, which holds only for JSON `POST` deliveries. [Verify Gitea webhooks](/webhooks/gitea/verify) has the details.

**Restricted outgoing hosts.** On an instance with `EGRESS_MODE` set to `strict`, your receiver's host must be in `ALLOWED_HOST_LIST` under `[security]`. Ask the administrator if test deliveries fail before reaching your server.

**Instance differences.** Because Gitea is self-hosted, the release your instance runs decides which events exist, and the administrator sets the timeout and cleanup policy. Check your instance's settings rather than assuming the defaults here.

**With Event Gateway:** Hookdeck verifies the signature on `POST` + `application/json` deliveries, then gives you one log of every attempt across your webhooks.