Hello Monks,

this is the second time I encounter problems with IPC::Shareable and I have no clue, what the reason might be:

I do not present the complete code overhere (it's just too big), but only the relevant parts.

I have a prog which runs four parallel processes, a parent (parallel process (PP) #1) launching two childs, on of them being a tcp-listener (#2), the other one (#3) forks a process (#4) which runs a BGP Process (see Net::BGP::Process) which registers BGP peers (the latter fork() being necessary since the BGP Process will finally remain in an event loop and the loop in PP #3 must not be blocked).

PP #2 should have access to one of the Peers (an object in Perl lingo) in PP #4. Therefore I tried to use IPC::Shareable to share this object amongst both PPs.

Here are the code fragments relevant:

PP #2:

sub run_ssl { my $heartbeat; my $parent_msg; my $sub = 'run_ssl()'; my $test; my $mesg; my $flags = ''; my $sock; my $client_socket; my $sel; my $ext_mesg; my $peer_ref; my $answer; #$sock = IO::Socket::SSL->new( # LocalAddr => $ssl_addr, # LocalPort => $ssl_port, # Listen => 5, # Reuse => 1, # Proto => 'tcp', # SSL_cert_file => 'server.crt', # SSL_key_file => 'server.key', #) || die "Can't bind TCP SSL port"; $sock = new IO::Socket::INET ( LocalHost => $ssl_addr, LocalPort => $ssl_port, Proto => 'tcp', Listen => 5, Reuse => 1, # Timeout => 1, ); if ( defined $sock ) { dbg( "${sub}: (Re-)Started SSL Socket Process" ); } else { dbg( "${sub}: IO::Socket::INET->new: $!" ); } $sock->timeout( 1 ); $sel = IO::Select->new( $sock ); $flags = fcntl( $from_parent_ssl, F_GETFL, 0 ) or die( "${sub}: Could not get flags for \$from_parent_ssl: $!\ +n" ); fcntl( $from_parent_ssl, F_SETFL, $flags | O_NONBLOCK ) or die( "${sub}: Could not set flags for \$from_parent_ssl: $!\ +n" ); if ( ! defined ( $pid = fork() ) ) { die( "${sub}: $@\n" ) } return $pid if ( $pid ); tie( $peer_ref, 'IPC::Shareable', 'glue', \%shareable_opts );

PP #4:

sub launch_bgp_proc { # Runs Net::BGP::Process in a separate process # my $pid; my $sub = 'launch_bgp_proc()'; my $peer; my $peer_ref; #my %peers; my $bgp; if ( ! defined ( $pid = fork() ) ) { die( "${sub}: $@\n" ) } return $pid if ( $pid ); tie( $peer_ref , 'IPC::Shareable', 'glue', \%shareable_opts); $bgp = Net::BGP::Process->new(); if ( defined $bgp ) { dbg( "${sub}: (Re-)Started BGP Process" ); } else { dbg( "${sub}: Net::BGP::Process: $!" ); } $peer = Net::BGP::Peer->new( Start => 1, ... [REMOVED TO HIDE IP ADRESSES] ResetCallback => \&bgp_callback_reset ); $peer_ref = $peer;

When I run this I get the error message (as far as I could analyze this it is thrown when trying to assign $peer to $peer_ref):

 at /usr/lib/x86_64-linux-gnu/perl/5.22/Storable.pm line 341, at /usr/local/share/perl/5.22.1/IPC/Shareable.pm line 524.

The documentation says that it should be possible to share objects via shared memory by assigning the object (or better: a non-tied referénce) to a tied variable.

Lincoln Stein in his book mentions that it should be possible to store a reference object in a tied/shared hash, so I tried this (only showing code for PP #4 which is currently the trouble maker, made appropriate changes to PP 2):

sub launch_bgp_proc { # Runs Net::BGP::Process in a separate process # my $pid; my $sub = 'launch_bgp_proc()'; my $peer; #my $peer_ref; my %peers; my $bgp; if ( ! defined ( $pid = fork() ) ) { die( "${sub}: $@\n" ) } return $pid if ( $pid ); tie( %peers , 'IPC::Shareable', 'glue', \%shareable_opts); $bgp = Net::BGP::Process->new(); if ( defined $bgp ) { dbg( "${sub}: (Re-)Started BGP Process" ); } else { dbg( "${sub}: Net::BGP::Process: $!" ); } $peer = Net::BGP::Peer->new( Start => 1, ... [REMOVED TO HIDE IP ADRESSES] ResetCallback => \&bgp_callback_reset ); $peers{ 'peer' } = $peer; ...

On running this variant, I get the same mess, i.e. the same error message (Can't store CODE items)

Any idea what the problem is here? Any suggestions how to share an object between the two processes?

Cheers

Bloehdian


In reply to IPC:Shareable: Sharing an object between parallel processes by Bloehdian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.