Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault during global destruction #19

Closed
calid opened this issue Mar 18, 2015 · 1 comment
Closed

segfault during global destruction #19

calid opened this issue Mar 18, 2015 · 1 comment

Comments

@calid
Copy link
Member

calid commented Mar 18, 2015

in some situations during global destruction, FFI::Platypus can dlclose libzmq before Socket/Context DEMOLISH routines have run... so when they do actually run they try to make ffi calls on a library that's no longer loaded leading to... kaboom.

this can (hopefully) be worked around by doing the FFI::Platypus attach equivlant of the FFI::Raw::Ptr trick of overriding the package DESTROY with a real underlying ffi destroy function:

    use base qw(FFI::Raw::Ptr);

    *_foo_new = FFI::Raw -> new(
      $shared, 'foo_new',
      FFI::Raw::ptr
    ) -> coderef;

    sub new {
      bless shift -> SUPER::new(_foo_new());
    }

    *DESTROY = FFI::Raw -> new(
      $shared, 'foo_free',
      FFI::Raw::void,
      FFI::Raw::ptr
    ) -> coderef;

    1;

    package main;

    my $foo = Foo -> new;
package Foo;

use FFI::Platypus::Declare;

attach [ foo_new => 'new' ] => [] => 'pointer';
attach [ foo_free => 'DESTROY' ] => [ 'pointer' ] => 'void';

1;

package main;

my $foo = Foo->new;
calid added a commit that referenced this issue Mar 19, 2015
This reverts commit e595d7d.

The EV version 3 thing (GH #17) turned out to be a red herring. The
segfault really has to do with race conditions during global
destruction.. for some reason using EV 3 just happens to trigger the
perfect storm of fail during global destruction.

So switch back to using condvar in the test and remove the EV 4 version
kludge (which doesn't fix the underlying issue anyways).

The more general segfault issue is now tracked in GH #19.
@calid
Copy link
Member Author

calid commented Mar 19, 2015

Unfortunately it doesn't look like setting *DESTROY to the native cleanup routines directly will fix all the race conditions during global destruction that result in the segfault. Either ffi calls need to be avoided completely in the object destructors during global destruction, or an upstream change to FFI::Platypus needs to be made.

@calid calid closed this as completed in 840ce27 Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant