1

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
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • Can you explain "_immediately after it prints_"? At what point in the code does it crash? From the question it seems that `thaw` worked fine ...? Also, why are you assigning to a plain array from `thaw` and why are you printing a plain array with `Dumper` (should be a reference)? – zdim May 03 '17 at 04:55
  • Is the server on another machine? If so, you should use `nfreeze`. – zdim May 03 '17 at 05:01
  • Are the classes from which the objects are serialized (on client) and to which it is deserialized (on the server) the same, or compatible enough? – zdim May 03 '17 at 05:07
  • Hi, i have used Dumper just to check if the array is reaching the server. it stops after the line "print Dumper(@got);" after a successful print. the server and client are on same machine but are different programs doing different jobs. – kaleemulla sharief May 03 '17 at 05:33
  • This is way off topic, but I see lazier English every day and it's frustrating. I'm sure you're aware that ***I*** should be a *capital letter*, and you probably know that you should use *articles* like ***a***, ***an***, and ***the***? I think it's only polite to use your best English when you're asking for free help. – Borodin Oct 09 '17 at 20:57
  • What is `$mq`? It's important to explain how your data us being transmitted. – Borodin Oct 09 '17 at 20:58

1 Answers1

5

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.

mob
  • 117,087
  • 18
  • 149
  • 283
  • 1
    Note that Storable provides [hooks](http://search.cpan.org/perldoc?Storable#Hooks) that can be used to define how to freeze and thaw objects of a class. – ikegami May 03 '17 at 17:23