Repository navigation
feat: SentTaskHandle and ReceivedTaskHandle - #2636
Open
nicolas-grekas wants to merge 16 commits into
Open
nicolas-grekas wants to merge 16 commits into
nicolas-grekas wants to merge 16 commits into
Conversation
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
2 times, most recently
from
September 7, 2026 07:56
c0eccbe to
6e571ec
Compare
This was referenced Sep 7, 2026
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
September 7, 2026 09:32
6e571ec to
23d3094
Compare
Contributor
Author
|
Pushed |
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
5 times, most recently
from
September 9, 2026 17:53
4c5af56 to
2b77a5b
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
5 times, most recently
from
September 14, 2026 06:16
e0be4ac to
fd177fc
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
11 times, most recently
from
September 18, 2026 16:58
a8f1a7f to
a9d72df
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
5 times, most recently
from
September 24, 2026 08:14
8925005 to
014aeff
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
September 30, 2026 16:06
014aeff to
9ad72ef
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
October 18, 2026 14:37
9ad72ef to
26399e0
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
October 27, 2026 09:35
26399e0 to
1f823e8
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
October 27, 2026 14:29
1f823e8 to
40898c3
Compare
Names were scoped per server so a script could address a background worker by name within its php_server. The namespaces of php#2635 and php#2636 do that now and no PHP API takes a worker name, so naming goes back to what main does: Caddy makes generated names unique, and the server label and the ServerMetrics interface are gone. The extension worker fixes leave too, main has the same bugs and they get a pull request of their own.
Since php#2660 worker threads come on top of num_threads and max_threads bounds the whole process. Background threads were the one exception, which took a reservation through calculateMaxThreads(), initPHPThreads() and the automatic max_threads. They now follow the same rule as HTTP workers.
HTTP workers wait for their ready point without a bound too, on builds without Zend max execution timers, so the bound belongs with both kinds of worker. Background workers keep the bound of max_execution_time where those timers exist, and the warning logged after 10 seconds elsewhere.
Init() waits for a background worker to reach its ready point, its first WorkerHandle::tick(). On a build with Zend max execution timers, max_execution_time ends a bootstrap that overstays; without them FrankenPHP disables that limit, so a script that parks before ticking, or one whose wake-up at start is lost, keeps the server start waiting for ever with a warning as the only trace. boot_timeout bounds that wait, 30 seconds by default, the same figure PHP's own max_execution_time uses for the bootstrap it does bound. The worker is then drained and stopped through the boot-failure path it already has, and Init() returns the name of the worker that never ticked. Zero waits for ever.
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
2 times, most recently
from
October 27, 2026 16:21
1792cb2 to
f651960
Compare
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
October 27, 2026 17:12
f651960 to
a1445d0
Compare
The timeout reported through a blocking send, so a second timeout could wait for room in startupFailChan for good, Init() with it. It now reports like the handlers do and moves the thread to ShuttingDown, so no run starts after the one that overstayed, whether the timeout lands in a run or between two failed boots. The 30s default now only applies where Zend max execution timers are missing, as the docs said: elsewhere max_execution_time bounds the bootstrap, and a set_time_limit() raising it is no longer cut short. Comments and docs that drifted are updated, and the thread budget and the Caddy directive get the tests they lacked.
frankenphp_get_vars() copied the snapshot inside a Go callback with its slot read-locked, so a bailout during the copy, past memory_limit or in an autoloader an enum triggers, left the lock held: the publisher and the next readers waited for good, Shutdown() with them. Snapshots are now counted references, the copy runs in C with no lock held and lets go of the snapshot on every path. The class name of an enum went to the autoloaders as the persistent string of the snapshot, so one keeping it pointed into memory the next publication freed, and readers raced on its refcount. The lookup now uses a request copy. A worker waiting on another one at boot now gives up when the start fails, so an HTTP worker reading vars in its bootstrap no longer keeps Init() waiting on a publisher that never comes up, and a Caddy JSON config no longer drops vars declared on an HTTP worker.
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
October 27, 2026 18:15
a1445d0 to
c11c074
Compare
The sanitizer jobs run without the Zend allocator, which enforces no memory_limit. A fatal error in the autoloader an enum triggers bails out on every allocator.
Calling SentTaskHandle::__construct() again replaced the task of the handle, so the first one was never closed on the sender's side: its descriptors and payload leaked, and a worker past the update buffer waited for good. A second construction now throws. A task whose wait for a thread ended on a restart or the shutdown was counted under no outcome; it is now "cancelled". A Caddy JSON config no longer drops tasks declared on an HTTP worker either.
nicolas-grekas
force-pushed
the
bgworker-tasks
branch
from
October 27, 2026 19:18
c11c074 to
61d9559
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2617 and #2635: review the commits on top of them.
Tasks for background workers, the task half of #2319. A worker declares the namespaces it receives, and a sender names the namespace:
SentTaskHandlewaits for a thread to pick the task up and throws on timeout, so a busy worker pushes back instead of queueing without bounds.WorkerHandle, so the loop of feat: background workers andFrankenPHP\WorkerHandle#2617 doesn't change.Io\Poll\Handlewith agetStream(), like the worker's.abandon(), or dropping the handle, gives up on the task, and a worker ending with a task open makes the sender's nextread()throw.The metrics follow:
frankenphp_busy_workersandfrankenphp_worker_queue_depthcount tasks, plusfrankenphp_worker_task_count{outcome}andfrankenphp_worker_task_timefor aMetricsimplementation that also implementsTaskMetrics.Left out compared to #2319: a queue ahead of pickup, and cancelling a task before it.