Subject: | decode_json fails after threads->new() called. |
Date: | Tue, 26 Jun 2018 17:26:27 +0000 |
To: | "bug-JSON [...] rt.cpan.org" <bug-JSON [...] rt.cpan.org> |
From: | "Pogrebinsky, Dmitry" <dpogrebi [...] akamai.com> |
Bug: decode_json fails after threads->new() was called.
Original version where I never observed this problem:
tlv-mprxg:etpcas_test dpogrebi$ uname -a
Darwin tlv-mprxg 16.7.0 Darwin Kernel Version 16.7.0: Tue Jan 30 11:27:06 PST 2018; root:xnu-3789.73.11~1/RELEASE_X86_64 x86_64
tlv-mprxg:etpcas_test dpogrebi$ perl -v | grep version
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
tlv-mprxg:etpcas_test dpogrebi$
New version where I faced the problem:
root@32ef9a90fdc3:/shared# uname -a
Linux 32ef9a90fdc3 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@32ef9a90fdc3:/shared# perl -v | grep version
This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi
Example:
use strict;
use JSON;
use threads;
sub system_thr
{sleep 1}
my $text='{
"device_id": "SjE4YHeUUTLQDUqgZQa3ilSrE=",
"key1": "Zg6S4vfaCCqeu6+8g+",
"key2": "2uyTUnft4679GDg5Sd",
"key_type": "hmac_sha"
}';
my $resp = decode_json $text ;
my $thr = threads->new(\&system_thr, 1);
for(my $i; !$thr->is_joinable(); $i++)
{ print "Waiting for joinable $i.\n"; sleep 1 }
$thr->join();
# Not works
$resp = decode_json $text ;
# temproral solution.
$resp = JSON->new->allow_nonref()->utf8->decode($text);
print join(',', keys %$resp),"\n";
Error message:
JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this) at aaa.pl line 22.