Potential Race condition in AnyEvent::Handle when a connect error occurs

Marc Lehmann schmorp at schmorp.de
Thu Feb 3 01:27:23 CET 2011


On Wed, Jan 26, 2011 at 11:26:37AM -0500, Ryan Bullock <rrb3942 at gmail.com> wrote:
> I receive the following error with my perl module on perl 5.12.2 with
> AnyEvent 5.31 and EV 4.03 when a connection error occurs and using the
> on_connect_error callback:

Thanks...

>  if ($self->{on_connect_error}) {
>                         $self->{on_connect_error}($self, "$!");
>                         $self->destroy;
>  } else {
>                         $self->_error ($!, 1);
>  }
> 
> This seems to happen because I am storing the AnyEvent::Handle in my
> blessed hash reference, but if a connect error occurs I am cleaning up
> and releasing everything in my hash reference. This is causing the
> AnyEvent::Handle object to get garbage collected (before destroy is
> called) because the reference to $self in the connect block is
> weakened.

I concur - thanks a lot for analyzing this problem, it will be fixed in
the next release, and sorry for the delay :)

> Here is a copy of a simply test case that seems to reliably recreate
> the problem (I hope this formats ok):

And especially thanks for the testcase, these are always handy :=)

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list