Add ZEND_OBJECT_TRANSFER_RELEASE so a transit shell can free what it owns - #20
Merged
Merged
Conversation
…owns transfer_obj had TRANSFER and LOAD only. A handler that puts C state into the transit shell — a refcounted pointer, a persistent string — has no way to get it back: free_obj never runs for a shell, so the state is unreachable once the shell is released. Handlers work around this by hand where they can (the async extension frees a closure snapshot from its release walk; the TrueAsync server frees its worker shells from the object that owns them), and leak where they cannot. The third kind closes that. Its contract: the handler frees its own C state and returns NULL, must not call default_fn, and must tolerate a NULL ctx, since a release runs outside a request. WeakReference and WeakMap are the two handlers in Zend; both branch on TRANSFER and treat everything else as LOAD, so they now refuse the new kind explicitly. Their transit wrappers own nothing of their own — the referent slots and the class-name copy are freed by the generic release walk.
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.
transfer_objhas TRANSFER and LOAD and nothing else. A handler that puts C state into the transit shell — a refcounted pointer, a persistent string — cannot get it back:free_objnever runs for a shell, so whatever the handler stored there is unreachable once the shell is released.Handlers work around this by hand where they can. php-async frees a closure snapshot from its release walk by recognising the shell through a non-NULL
properties. The TrueAsync server frees its worker shells from the object that owns them (http_server_release_worker_shell, added after issue php#93 found ~10KB leaking per reload rotation). Where no owner exists, the state leaks: aTrueAsync\Roomtransferred into aThreadPooltask leaked its topic-hub reference — 21,608 bytes of hub plus a persistent topic string — with nobody to free them.The third kind gives the class a say. Contract: the handler frees its own C state and returns NULL, must not call
default_fn, and must tolerate a NULLctx, because a release runs outside a request. php-async dispatches it fromthread_release_transferred_object(separate PR).WeakReferenceandWeakMapare the onlytransfer_objhandlers in Zend, and both branch on TRANSFER while treating everything else as LOAD — reaching that branch with a NULLctxand a NULLdefault_fncrashes. They now refuse the new kind explicitly. Their transit wrappers own nothing of their own: the referent slots and the class-name copy are freed by the generic release walk.Measurements
Built and installed locally, then ran the whole async suite:
ext/async3 failed, all three pre-existing (__DIR__resolves the ext/async symlink, so theirincludeof a php-src helper four levels up misses). Before the WeakReference and WeakMap guards, six thread-transfer tests died withTermsig— which is what the guards are for, and what a handler hitting its LOAD branch on the new kind looks like.