Item14025: JsonRpcContrib requires allow_nonref (when using JSON-XS v3.02).

pencil
Priority: Urgent
Current State: Closed
Released In: 2.1.1
Target Release: patch
Applies To: Extension
Component: JsonRpcContrib, ModPerlEngineContrib
Branches: Release02x01 master Item14033 Item13897 Item14380 Item14537
Reported By: MarkusUeberall
Waiting For:
Last Change By: ProjectContributor
(NB the below is the result/a side effect of updating a number of Perl modules two days ago; I didn't have time to look more closely at the underlying problem, but starting by adding allow_nonref does not seem to be a bad idea at first glance; see also Item14024)
The following warning seemingly breaks configure in my installation ("Loading ..." forever):
| 2016-03-15T21:02:15+01:00 warning | hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /var/www/apps/foswiki/lib/Foswiki/Contrib/JsonRpcContrib/Response.pm line 135.
 at /var/www/apps/foswiki/lib/Foswiki/Contrib/JsonRpcContrib/Response.pm line 135.
        Foswiki::Contrib::JsonRpcContrib::Response::encode(Foswiki::Contrib::JsonRpcContrib::Response=HASH(0x7f0d8d849480)) called at /var/www/apps/foswiki/lib/Foswiki/Contrib/JsonRpcContrib/Response.pm line 48
        Foswiki::Contrib::JsonRpcContrib::Response::print("Foswiki::Contrib::JsonRpcContrib::Response", Foswiki=HASH(0x7f0d8ce8c278), "code", -32700, "message", "Parse error - invalid json-rpc request: JSON text must be an "...) called at /var/www/apps/foswiki/lib/Foswiki/Contrib/JsonRpcContrib/Server.pm line 89
        Foswiki::Contrib::JsonRpcContrib::Server::__ANON__(Foswiki::Contrib::JsonRpcContrib::Error=HASH(0x7f0d8c004b28), SCALAR(0x55afee321f00)) called at /var/www/.plenv/versions/5.22.1-ithreads-shrplib/lib/perl5/site_perl/5.22.1/Error.pm line 345
        eval {...} called at /var/www/.plenv/versions/5.22.1-ithreads-shrplib/lib/perl5/site_perl/5.22.1/Error.pm line 335
        Error::subs::run_clauses(HASH(0x7f0d8d849d20), Foswiki::Contrib::JsonRpcContrib::Error=HASH(0x7f0d8c004b28), undef, ARRAY(0x7f0d8c60d110)) called at /var/www/.plenv/versions/5.22.1-ithreads-shrplib/lib/perl5/site_perl/5.22.1/Error.pm line 432
        Error::subs::try(CODE(0x7f0d8d5dd990), HASH(0x7f0d8d849d20)) called at /var/www/apps/foswiki/lib/Foswiki/Contrib/JsonRpcContrib/Server.pm line 90
        Foswiki::Contrib::JsonRpcContrib::Server::dispatch(Foswiki::Contrib::JsonRpcContrib::Server=HASH(0x7f0d8d4cd378), Foswiki=HASH(0x7f0d8ce8c278)) called at /var/www/apps/foswiki/lib/Foswiki/Contrib/JsonRpcContrib.pm line 35
        Foswiki::Contrib::JsonRpcContrib::dispatch(Foswiki=HASH(0x7f0d8ce8c278)) called at /var/www/apps/foswiki/lib/Foswiki/UI.pm line 374
        Foswiki::UI::__ANON__() called at /var/www/.plenv/versions/5.22.1-ithreads-shrplib/lib/perl5/site_perl/5.22.1/Error.pm line 421
        eval {...} called at /var/www/.plenv/versions/5.22.1-ithreads-shrplib/lib/perl5/site_perl/5.22.1/Error.pm line 413
        Error::subs::try(CODE(0x7f0d8d3f31b8), HASH(0x7f0d8ce8c080)) called at /var/www/apps/foswiki/lib/Foswiki/UI.pm line 500
        Foswiki::UI::_execute(Foswiki::Request=HASH(0x7f0d8d509268), CODE(0x7f0d8c09e7e8), "jsonrpc", 1) called at /var/www/apps/foswiki/lib/Foswiki/UI.pm line 326
        Foswiki::UI::handleRequest(Foswiki::Request=HASH(0x7f0d8d509268)) called at /var/www/apps/foswiki/lib/Foswiki/Engine/Apache.pm line 91
        Foswiki::Engine::Apache::run(Apache2::RequestRec=SCALAR(0x7f0d8d5fa048)) called at -e line 0
        eval {...} called at -e line 0.
 |

Toggling TRACE in JsonRpcContrib/Request.pm shows the following when directly invoking configure after restarting the web server:
| 2016-03-15T23:10:54+01:00 debug | - JsonRpcContrib::Request - data={"jsonrpc":"2.0","method":"getspec","params":{"get":{"parent":{"depth":0}},"depth":0},"id":"iLoad-schema_0"} |

Can't repro. Can you find out what the value of $message actually is?

-- MichaelDaum - 17 Mar 2016

The complete message reads
Parse error - invalid json-rpc request: JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)

Update: I was able to identify JSON-XS (v3.02) as the culprit in my case (an earlier version used to work). See Item14024 (also refers to a related CPAN bug report which has some details).

-- MarkusUeberall - 17 Mar 2016

As noted in Item14024, this seems to only manifest when ModPerl is active. It does not fail with FastCGI.

-- GeorgeClark - 22 Mar 2016

I've found some other references about issues under mod_perl and JSON::XS. It appears that comments in the XS module claim that it's not thread safe, so use in a mod_perl environment can be unpredictable. See CPAN:Cpanel::JSON::XS for one attempt to build a better version. CPAN:JSON::XS states explicitly "This module is not guaranteed to be thread safe and there are no plans to change this ..."

-- GeorgeClark - 26 Mar 2016

We've decided in the release meeting to include a workaround, which has just been merged and will be released in 2.1.1 and 2.2.0.

-- JanKrueger - 04 Apr 2016
 
Topic revision: r13 - 31 Jan 2018, ProjectContributor
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy