Possible minor bug in AnyEvent :: Impl :: POE -> io

Andreas Breslau abreslau at smail.uni-koeln.de
Mon Mar 21 19:29:07 CET 2016


Hi Marc,

I think I have to start with the original problem ;-)
I have a small script alternating calling an external program (with 
Anyevent::Run) and sleeping for some time.
I have attached a minimal working example.

Without "use AnyEvent::Impl::POE;" in the main part, everything is fine.
But when POE is used, in each iteration a filedescriptor is ceated which 
remains open (visible in /proc/pid/fd/ under Linux).
After a while the program crashes because the maximum number of 
filedescriptors is used.

I traced back the creation of the filehandle corresponding to these 
non-released filedescriptors down to the location mentioned in the 
original mail.
Since the duplicated filehandle was the one remaining open, it seemed 
obvious to me that something like a "close $fh" is missing.
But a bug in POE or more likely in my code is also possible.

Please have a look yourself.

Cheers and thanks
Andreas



Marc Lehmann wrote:
> On Thu, Mar 17, 2016 at 06:36:03PM +0100, Andreas Breslau <abreslau at smail.uni-koeln.de> wrote:
>   
>> In AnyEvent :: Impl :: POE the filehandle ($fh) created in sub io() with
>> AnyEvent::_dupfh and passed to POE::Session->create() is not closed/deleted
>> in stop => sub {}.
>>     
>
> Hi!
>
> It would be a bug if it were closed - but what do you mean with deleted?
> Shouldn't POE free resources associated with a session when the session
> gets destroyed?
>
> Apparently not, if POE holds to it, but I don't know how to make POE free
> resources.
>
>   
>> I fixed this problem for me be by changing the stop callback to:
>>     
>
> If you close the fh when the session is destroyed, then the fh is closed
> whenever a watcher is destroyed (because the watcher is the session), which
> would introduce a bug.
>
> This looks like a bug in POE or maybe in how you use the code - do you have a
> small example program that I can check that shows the problem?
>
>   
>> I found no other place where this duped filehandle is closed, so this might
>> be a bug which should be fixed.
>>     
>
> Perl automatically closes file handles that are destroyed. The problem
> you describe happens when something keeps a reference to the fh that
> shouldn't.
>
>   
>> Or does this only occur on my system and I missed something?
>>     
>
> It doesn't usually depend on your system or configuration, only with how your
> program, AnyEvernt or POE behave.
>
>   

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pl
Type: text/x-perl
Size: 901 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20160321/34377d7e/attachment.pl>


More information about the anyevent mailing list