Call to thaw throwing segmentation fault

119 views Asked by At

I am using the FreezeThaw module to send serialized objects from a client to a server. It is working fine for array references with a limited number of entries, but when I do the same for a bigger array of blessed objects the server is stopping with

Segmentation fault (core dumped)

Below is what I am using

Client:

my $message = freeze $_[1]; # encode_json
$mq->publish($channel_id, $routing_key, $message);

Server:

my $message  = $payload->{body} ;
my @got = thaw $message;
print Dumper(@got);

When I use the below array reference it reaches the server, but immediately after it prints, the server stops with a segmentation fault error.

$VAR1 = [
          [
            bless( {
                     'oidptr' => bless( do{\(my $o = '140488241049968')}, 'netsnmp_oidPtr' )
                   }, 'NetSNMP::OID' ),
            '600',
            67
          ],

... approximately 200 lines repeated
1

There are 1 answers

1
mob On BEST ANSWER

Freeze/thaw won't work on NetSNMP::OID objects.

NetSNMP::OID uses XS code. The XS code allocates a data structure in C, and makes the address of that data available in Perl. The only data that is stored in the Perl object, and the only data that gets saved and restores with freeze and thaw, is that address. The contents of that address will not survive across processes or across a client-server boundary on different machines.

The crash occurs because the server takes what is basically a random memory address, and tries to make sense of it as a netsnmp_oid_t data structure.

You will have to come up with another way to access and serialize the actual contents of your NetSNMP::OID object.