On Tue Feb 08 13:30:47 2011, dfrett wrote:
Show quoted text> On Mon May 17 12:48:17 2010, DPAVLIN wrote:
> > I never managed to reproduce this problem. Do you still see this
> problem?
>
> I just ran into this error on the latest code from github, doing a bit
> of debugging I found that
> the refcount of SVs in the _PLfuse_callbacks array get messed up under
> high threaded load.
>
> I was able to pretty reliably reproduce this by using the
> loopback_t.pl example on a directory
> with a lot of files and subdirectories, then running the following
> command on multiple
> terminals: "while true; do ls -alR fuseTest; done".
>
> The problem seems to go away by removing the call to SvSHARE on the
> SVs being stored in
> the array. This call shouldn't be necessary because the callback SVs
> will be automatically
> cloned to other threads when perl_clone is called, and are never
> updated after fuse_loop_mt is
> started.
>
> This would seem to indicate that this may be a threads::shared
> refcount race condition and
> be triggered again by passing in an already shared variable for a
> callback. I don't have
> enough perl threads knowledge/experience or time right now to be able
> to track this down
> any further to find and fix any potential underlying issues.
>
> I pushed a patch up to github here:
https://github.com/frett/perl-
> fuse/tree/RT34284
>
I tracked down the actual cause of this bug to the fact that the callbacks were not being
stored in a thread safe manner and all threads were accessing the SV's referencing the
callbacks from the master thread. This led to race conditions with ref counting when the SV
had the SvSHARE magic on it were passed to call_sv.
I fixed the issue by implementing thread-safe static data storage utilizing the MY_CXT
mechanism documented here:
http://search.cpan.org/~rjbs/perl-
5.12.3/pod/perlxs.pod#Safely_Storing_Static_Data_in_XS
I have tested this on perl5.10.1 and have not been able to reproduce the race condition.
Another potential side-effect of this fix is the support for closures as callbacks due to the
callback SV's being cloned to new threads the same way all other perl data is cloned. I have
not tested this functionality yet to know if this does definitely work now or not.
I made created a pull request on github with my patch here:
https://github.com/dpavlin/perl-fuse/pull/2
-Daniel