I am hoping someone here can point me in the right direction. I have a message processing system written in perl using JSON as the primary transport encoding. The main process receives STOMP messages using AnyEvent::STOMP. Those messages are encoded in json by php and received by perl and decoded. The messages are JSONRPC messages with a "method" and "params". When I decode them, I then re-encode the params and use a AnyEvent::JSONRPC::TCP::Client to send them to the AnyEvent::JSONRPC::TCP::Servers listening on unix sockets. This is a service I have been running for 2+ years, and the bit of code responsible for processing the stomp messages has remained unchanged for most of the life of the project. I am running perl-5.18 in a Docker container based on ubuntu:14.04.
I recently flushed all of my layer caches and built the entire container from scratch, and I am now having a problem with the JSON encoding which has me frazzled. I've spent 8+ hours trying to figure out specifically what might have changed, but I'm coming up with nothing. In my stomp client process I have always used JSON->new->allow_nonref as my encoder because some of the "params" that come through are an array once decoded and some are not. Using allow_nonref made this something I could handle without having to change anything based on how the message was received. However, after building the new image I found the following exception messages in my log, and the messages are not making it to the JSONRPC::Server any longer.
unhandled callback exception on event (MESSAGE, AnyEvent::STOMP::Client=HASH(0x7432b18), HASH(0x1a9da520) {"method":"echo","params":[{"Deployment":{"id":"57276a74-8790-48aa-b7d6-42480a6e0303","status":268435970,"comment":"marathon| Creating new application for website 1088 in marathon","website_id":1088,"district":"devel"}}]}): hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /usr/local/lib/perl/5.18.2/AnyEvent/Handle.pm line 1135The AnyEvent::Handle module line 1135 is using the encode method of JSON::XS->new->utf8. I tried to reproduce this issue by using the same encode method on the same data via perl cli and I am unable. I modified the module code to have it dump the data it was receiving as it's $ref input, and it is as I suspected a valid hashref. I used that dumped hashref, I tried changing from allow_nonref to encode/decode it in different ways before sending it to the client, but nothing I do will reproduce the issue in my tests.
use JSON::XS; use Data::Dumper; my $json = JSON::XS->new->utf8; my $input = '{"method":"echo","params":[{"Deployment":{"id":"57276a74- +8790-48aa-b7d6-42480a6e0303","status":268435970,"comment":"marathon| +Creating new application for website 1088 in marathon","website_id":1 +088,"district":"devel"}}]}'; print Dumper { input => $input, output => $json->decode($input), re_en +coded => $json->encode($json->decode($input)) }; $VAR1 = { 'input' => '{"method":"echo","params":[{"Deployment":{"id":" +57276a74-8790-48aa-b7d6-42480a6e0303","status":268435970,"comment":"m +arathon| Creating new application for website 1088 in marathon","webs +ite_id":1088,"district":"devel"}}]}', 're_encoded' => '{"params":[{"Deployment":{"status":26843597 +0,"district":"devel","comment":"marathon| Creating new application fo +r website 1088 in marathon","id":"57276a74-8790-48aa-b7d6-42480a6e030 +3","website_id":1088}}],"method":"echo"}', 'output' => { 'params' => [ { 'Deployment' => { 'id' => '572 +76a74-8790-48aa-b7d6-42480a6e0303', 'website_id' + => 1088, 'comment' => + 'marathon| Creating new application for website 1088 in marathon', 'district' = +> 'devel', 'status' => +268435970 } } ], 'method' => 'echo' } };
In reply to JSON encoding issues by sedninja
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |