Gitea webhooks in production: duplicates, retries and timeouts
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 overview, every event type is on Gitea webhook events, and signature verification code is on Verify Gitea webhooks.
At a glance
| Problem | What to do | With Event Gateway |
|---|---|---|
| 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 | Redeliver failures by hand before the instance cleans them up | Stores each delivery and retries to your service on your schedule |
| Duplicates | Make handlers idempotent; key on what changed, not X-Gitea-Delivery | Drops repeats based on the fields you choose |
| Choosing events | Route on X-Gitea-Event-Type; subscribe narrowly | Filters and routes on headers and body |
| Testing | Use Test Delivery, and forward to localhost with a CLI | Forwards to localhost and replays past events |
| 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
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:
- Verify the signature, enqueue the event and respond straight away. See why to process webhooks asynchronously.
- Keep the request path free of calls to other services.
- 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
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 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:
- Keep the endpoint up during deploys, because a delivery that fails then won't come back on its own.
- 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 towards your service on your schedule. An outage on your side no longer means a manual redelivery session.
Duplicate Gitea webhooks
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:
- Build an idempotency key from the object and its state, such as a push's
afterSHA, or a pull request'snumberwith itsaction. See our guide to webhook idempotency. - Store processed keys with a unique constraint.
- Wrap the side effect and the key record in one transaction.
With Event Gateway: Hookdeck's deduplication can drop repeats based on the fields you choose.
Choosing and routing Gitea 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_. A handler on the group treats a label change as just another issue event. The group names can also mislead: a pull_request_comment trigger arrives under the group issue_comment, while the group pull_request_comment means the trigger pull_.
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:
- Switch on
X-Gitea-Event-Type, then onactionwhere the event has one.create,delete,fork,pushandstatushave none. - Under Trigger On, prefer a custom selection to All Events. Selecting
pull_request_reviewsubscribes you to the approved, rejected and comment review events, and it never arrives under that name. - Add a branch filter for ref events, and check
refin your handler if the filter is broad.
With Event Gateway: Hookdeck 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
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:
- Use Test Delivery to check the URL, secret and content type.
- Read Recent Deliveries for the request and response of each attempt, and use Redelivery to replay a real event to your handler.
- 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 receives webhooks on your machine without a public server, and you can replay past events with one click.
Other Gitea webhook 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 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.
Stop losing Gitea events to a 5 second timeout.
Gitea's docs describe no automatic retries. Hookdeck Event Gateway accepts each Gitea delivery, verifies the signature on POST + application/json webhooks, queues events and retries to your service on your schedule.