|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patcheswr_weakref-fix-dtor-release (last revision 2015-02-27 00:09 UTC by p at wspnr dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-01-11 16:34 UTC] colder@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: colder
[2016-01-11 16:34 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 05:00:01 2025 UTC |
Description: ------------ Under certain conditions, unsetting a Weakref instance that has acquired and NOT released a strong reference will result in an exception being thrown during shutdown. This seems to cause PHP to shut down uncleanly, and the next request (FPM SAPI) will fail with a cryptic error (e.g. re-declaration of a function that is only declared once). After a few requests, the FPM child process will terminate due to a segmentation fault. I had to apply a patch as a stopgap on our dev server since every other request was failing. The problem seems to be within wr_weakref_ref_dtor: it sets valid to 0 but does not release the reference. During shutdown, wr_weakref_object_free_storage calls wr_weakref_ref_release which fails as valid is now 0. Adding a loop to release the reference in wr_weakref_ref_dtor fixes the problem. Version 0.2.5/0.2.6 of Weakref. Additional note: the documentation for this extension does not make it clear that acquire() and release() need to be called in pairs. The code this first surfaced called acquire() multiple times, and release() only once. Perhaps this could be added to the documentation? Test script: --------------- $wr = []; for($i = 0; $i < 2; $i++) { $c = new stdClass(); $wr[$i] = new Weakref($c); $wr[$i]->acquire(); } unset($wr[0]); Expected result: ---------------- (no output) Actual result: -------------- Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to correctly release the reference on free' in [no active file] on line 0