mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 07:59:03 +00:00
## Problem The self-hosted Functions guide lists worker timeouts and idle cleanup, but never says that a running worker serves later requests. The Docker guide says the main worker loads each function from disk per request, which suggests top-level setup runs on every request. Related to [FDBKIN-22732](https://linear.app/supabase/issue/FDBKIN-22732/clarify-edge-functions-worker-lifecycle-and-reuse-strategy-for-self) Closes [DOCS-1799](https://linear.app/supabase/issue/DOCS-1799/explain-how-self-hosted-edge-functions-reuse-workers-across-requests) ## Solution A new "Worker lifecycle" section on the self-hosted Functions guide explains that the default `per_worker` policy sends requests to a function's running workers. Concurrent cold requests can start up to one worker per CPU, and later requests rotate across them. It says that top-level code runs once per worker, so heavy setup belongs there. It also lists the events that stop a worker from taking new requests, including retirement at half of `workerTimeoutMs`, links to the existing timeout and cleanup sections, and names the settings that keep workers alive longer. The Docker guide's sentence now says that a restart stops running workers, so the next request picks up changed code. ## How to verify 1. Open https://docs-git-tedd-docs-1799-supabase.vercel.app/docs/guides/self-hosting/self-hosted-functions#worker-lifecycle and https://docs-git-tedd-docs-1799-supabase.vercel.app/docs/guides/self-hosting/docker#accessing-edge-functions. 2. The Worker lifecycle section says that requests go to a running worker for the function, that concurrent cold requests might each start a worker up to the number of CPUs, and that later requests rotate across those workers. 3. It says that top-level code runs once per worker, that heavy setup goes at the top level, and that top-level state belongs to one worker. 4. It lists reaching half of `workerTimeoutMs`, no requests, idle-worker cleanup, an error or resource limit, and a service restart as events that stop a worker from taking new requests, and says a new worker starts when the function has none left. The links to Timeout errors, Idle-worker cleanup, Per-worker memory limit, and Container memory budget go to those sections. 5. It names `requestAbsentTimeoutMs` and `workerTimeoutMs` as the settings to raise to keep workers alive longer. 6. The Docker guide no longer says functions load from disk per request, and still says a restart picks up new or changed function code. ## Checks Ran `pnpm turbo run lint typecheck` on the changed packages and `pnpm exec oxfmt --check` on the changed files. Checked the facts against `docker/volumes/functions/main/index.ts` and `docker/docker-compose.yml` in this repo, and against `supabase/edge-runtime` at `v1.79.2` (the compose image tag): `cli/src/flags.rs` (`--policy` default), `crates/base/src/worker/pool.rs` (worker reuse, rotation, concurrent creation, and retirement), `crates/base/src/worker/supervisor/strategy_per_worker.rs` (early retirement at half of the wall-clock limit), and `ext/workers/user_workers.js` (`forceCreate` default). Docs tests need Docker and were skipped. Reuse wasn't tested against a running stack. ## Checklist - [x] I have read the [Contributing Guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] I have checked that the change follows the docs style guide - [ ] I have checked that the change works in the preview deployment ## Feedback for Tedd To ask Tedd for a change to this PR, reply in Tedd's session on [DOCS-1799](https://linear.app/supabase/issue/DOCS-1799/explain-how-self-hosted-edge-functions-reuse-workers-across-requests). Tedd doesn't read comments on this PR. --------- Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
Supabase Docs
This directory contains the Next.js app for supabase.com/docs.
Guides live in content/ as MDX. Reference pages are generated from the specs in spec/: OpenAPI, SDKSpec, ConfigSpec, and CLISpec. Some sections come from other repositories.
Where to go
- To write a page, follow the style guide.
- To find where a page lives, add one, or update generated reference docs, use the contributing guide. Library maintainers start at Reference structure.
- To use an agent, use the AI agent skills for docs authoring. Those skills include framing a page and placing it in the information architecture.
- To run the site locally, use the developers' guide.
- To add or change a redirect, read
lib/redirects/README.mdfirst.