You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a BackgroundScope opaque type (int under the hood; obtain values
via NextBackgroundWorkerScope) so each php_server block gets its own
isolation boundary for background workers. Zero is the global/embed
scope.
- backgroundLookups map[BackgroundScope]*backgroundWorkerLookup
replaces the single global backgroundLookup. Each scope has its own
named registry + catch-all so two blocks can declare bg workers with
the same user-facing name without colliding.
- buildBackgroundWorkerLookups iterates declarations into their scope's
lookup; each declaration still owns its own registry. registry.declared
remembers the *worker for a named declaration so lazy-start (num=0)
reuses it without scanning the global workersByName map (which is not
scope-aware for bg workers).
- getLookup(thread) resolves the active scope from the calling thread:
worker handler -> request context -> global (0). Scopes that declared
their own workers stay strictly isolated; an empty scope falls through
to the global lookup so embed-mode workers stay reachable.
- Go options: WithWorkerBackgroundScope tags a declaration; the new
WithRequestBackgroundScope tags a request so ensure() from a regular
HTTP request resolves to the right block's lookup.
- Caddy wiring: FrankenPHPModule.Provision allocates one scope per
module instance (idempotent across re-provisions) and threads it into
worker declarations and ServeHTTP.
- workersByName collision check now skips bg workers; they resolve via
their scope's lookup, so the same PHP-visible name can appear in two
scopes without tripping the duplicate guard.
- C side: go_frankenphp_ensure_background_worker now takes the calling
thread index so getLookup can resolve the scope from the active
handler / request context.
Tests:
- TestNextBackgroundWorkerScopeIsDistinct: counter hands out unique
non-zero scopes.
- TestBackgroundWorkerSameNameDifferentScope: two named bg workers with
the same user-facing name in distinct scopes both Init successfully
and own distinct registries.
- TestBackgroundWorkerCatchAllPerScope: ensure() in scope A consumes
scope A's catch-all only; scope B's catch-all stays empty. Verified
by inspecting the per-scope lookup and the live workers slice via
package-internal access.
Deferred to follow-ups: pools (num > 1 per named worker, max_threads > 1
for named workers), multiple declarations sharing one entrypoint file
in one scope, FRANKENPHP_WORKER_BACKGROUND server flag, batch ensure.
0 commit comments