php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59680 Reference counting bug
Submitted: 2011-03-21 18:55 UTC Modified: 2017-10-24 04:46 UTC
From: evert at rooftopsolutions dot nl Assigned:
Status: Suspended Package: libevent (PECL)
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
 [2011-03-21 18:55 UTC] evert at rooftopsolutions dot nl
Description:
------------
When an event resource (returned from event_new) is added with event_base_set / event_add, but event_base_loop is called from a different function, the event is never triggered.

This is because the event_resource is garbage collected. If I make sure the event stays in some kind of scope (I added it to $GLOBALS for testing) it does work.

So this tells me that the reference count is not increased when the event is added with event_base_set.




Patches

proposed_fix (last revision 2013-01-31 19:15 UTC by tony2001@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-22 05:55 UTC] tony at daylessday dot org
Please provide a short reproduce case.
From the code I see that the refcount IS increased when needed.
 [2011-03-22 15:52 UTC] evert at rooftopsolutions dot nl
I hope this is short enough:

http://pastebin.com/33jqgfP8

As you can see there's a $GLOBALS line commented out. If you remove the comments, it will work as expected. If that line is commented the event is garbage collected and event_base_loop returns 1.

Although it could be considered a feature that when an event leaves regular php scope, I do consider this un-php-like. I expect to be forced to manually call event_free.

Does this make sense? Otherwise I'll happily add more details.


Off-topic: I noticed you're the main developer for this package. I have some burning questions, is there any chance I can email you directly?

In any event, thank you for checking this out!
 [2013-01-25 08:52 UTC] tony2001@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: tony2001
 [2013-01-31 19:15 UTC] tony2001@php.net
The following patch has been added/updated:

Patch Name: proposed_fix
Revision:   1359659744
URL:        https://bugs.php.net/patch-display.php?bug=59680&patch=proposed_fix&revision=1359659744
 [2013-01-31 19:16 UTC] tony2001@php.net
Sorry it took so long, could you plz try the patch attached?
I know it does fix this particular issue and I'm more concerned about the things it 
might break instead.
 [2013-01-31 19:16 UTC] tony2001@php.net
-Status: Assigned +Status: Feedback
 [2013-01-31 19:53 UTC] evert at rooftopsolutions dot nl
No worries about the timeframe :).

At the time (nearly 2 years ago) I was just experimenting with libevent, but it never really went beyond the experiment.

So I'd be happy to try the patch, although it would be limited to just trying out my simple test case from this bug report, I don't have a 'real' system to test this with.

Let me know if this would still help you, I will definitely try it then.
 [2013-02-01 06:31 UTC] tony2001@php.net
That's exactly the problem here - I don't have a real system to test it, since I don't 
use libevent extension myself =)
 [2013-02-01 11:39 UTC] evert at rooftopsolutions dot nl
Hi,

My tests are succeeding with this patch. I'm going to attempt to also contact someone in the community; Hopefully to get a second eye on this.
 [2013-02-01 19:58 UTC] igor at wiedler dot ch
I just tried the proposed patch and ran it through the script[0] we have in 
reactphp for detecting leaks. The patch causes memory usage to keep increasing, as 
such I would say that the patch causes a memory leak.

If you need help setting up the test case for reproduction, you can find me in 
#reactphp on freenode.

[0]: https://github.com/reactphp/react/blob/master/examples/test-memory.php
 [2013-02-02 19:36 UTC] tony2001@php.net
Yes, would be nice to a have a working reproduce script.
The one from github doesn't work atm: require('./examples/../vendor/autoload.php): 
failed to open stream: No such file or directory
 [2013-02-02 23:41 UTC] igor at wiedler dot ch
Yeah, it depends on composer[0] to fetch the dependencies and install generate the 
autoload file. I can help you run composer, or make a standalone zip if that 
helps. Just let me know.

[0]: http://getcomposer.org/
 [2013-02-03 12:31 UTC] tony2001@php.net
Do you really need a whole framework for that?
 [2013-02-03 13:51 UTC] igor at wiedler dot ch
Granted, for a standalone project with no dependencies it may seem like overkill. 
As soon as you depend on 10+ packages and need to configure autoloading manually, 
you will know why. Composer adoption is huge, I think it's safe to say that it's a 
de-facto standard in the PHP community (as far as that is possible in PHP).

Either way, I've made a `vendors` branch on my fork[0] of the repo which includes 
vendors+autoload.php. You should be able to check that out and run `php 
examples/test-memory.php`. I hope that helps!

[0]: https://github.com/igorw/react/tree/vendors
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-02-18 02:24 UTC] evert at rooftopsolutions dot nl
Feedback was provided!
 [2013-02-18 08:36 UTC] tony2001@php.net
-Status: No Feedback +Status: Assigned
 [2017-10-24 04:46 UTC] kalle@php.net
-Status: Assigned +Status: Suspended -Assigned To: tony2001 +Assigned To:
 [2017-10-24 04:46 UTC] kalle@php.net
I'm gonna close this as the libevent package on PECL had no had a release for 4 years, and there haven't really been much acitivity since. If development picks back up then this report should be re-opened
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC