Fixing problems with Cpanel::JSON::XS module

From Integrics Wiki
Revision as of 23:22, 23 August 2024 by Rodolfojcj (talk | contribs) (Typo fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Enswitch 4.1 and newer versions require Crypt::JWT, which depends on CryptX.

In some systems, there are some known issues related with Perl's Cpanel::JSON::XS module, which is not required by Enswitch, but could have been installed either as an operating system package or from CPAN.

Those known issues and the ways to deal with them are detailed below.

Message Can't locate Cpanel/JSON/XS.pm in @INC appears in the system log files

Symptom

The operating system log files like /var/log/syslog or /var/log/messages show lines saying something like this:

 localhost systemd[1]: Started Kamailio server.
 localhost /sbin/kamailio[32260]: ERROR: app_perl [kamailioxs.xs:1041]: XS_Kamailio__Message_log(): perl error: Can't locate Cpanel/JSON/XS.pm in @INC (you may need to install the Cpanel::JSON::XS module) (@INC contains: /opt/enswitch/current/perllib /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl) at /usr/local/lib/x86_64-linux-gnu/perl/5.26.1/CryptX.pm line 14.

Cause

The installed module CryptX tries to load the Cpanel::JSON::XS module but can not find it.

This happens when a version <= 0.072 of CryptX is used.

What to do?

  • Do nothing. This is because those log lines are harmless.
  • Install Cpanel::JSON::XS with the operating system package manager tools or directly from CPAN, for example with any of these commands:
    • For Debian or Ubuntu based systems: apt-get install libcpanel-json-xs-perl.
    • For CentOS based systems: yum install perl-Cpanel-JSON-XS.
    • Directly from CPAN: cpanm Cpanel::JSON::XS.
  • If Cpanel::JSON::XS was installed, restart Kamailio. After this, the system log should not add lines with the mentioned messages.

Segmentation faults for the Apache web server are reported in the system log files

Symptoms

  • The operating system log files like /var/log/syslog or /var/log/messages show lines saying something like this:
 localhost kernel: [10306754.605002] apache2[4013806]: segfault at 8 ip 00007fb92a1ebf47 sp 00007fff905b0cb8 error 4 in XS.so[7fb92a1eb000+f000]
 localhost kernel: [10306754.605011] Code: 1f 40 00 f3 0f 1e fa 48 63 15 dd 30 01 00 48 8b 87 78 0b 00 00 48 83 6f 78 04 48 8b 04 d0 48 8b 70 30 48 c7 40 30 00 00 00 00 <8b> 56 08 83 fa 01 76 11 83 ea 01 89 56 08 c3 66 2e 0f 1f 84 00 00
  • The Apache error log shows lines like this one:
 [:error] [pid 4014780] Undefined subroutine &Enswitch::Utilities::file_delete called at /usr/local/lib/site_perl/Enswitch/Utilities.pm line 790.
  • The web browser or any other HTTP client sometimes receives the expected response, but other times receives an error message, like a 500 status code indicating a failure in the server side. This happens for the same input parameters and is not reproducible at will.
  • This has been observed in Ubuntu versions 20.04 and 21.04, but could also happen in other versions or with other distributions.

Cause

CryptX will use Cpanel::JSON::XS if both of these happen:

If CryptX is using Cpanel::JSON::XS as the preferred implementation of JSON::XS, a bug that seems to affect the XS.so file provided by Cpanel::JSON::XS will cause the mentioned segmentation faults.

That XS.so file is a shared library that comes from compiled C code.

There is an issue report in the official sources repository of the Cpanel::JSON::XS that offers more details.

What to do?

Apply all of the following:

  • Remove the Cpanel::JSON::XS module. Depending on the way used to install it, any of these commands could be used:
    • For Debian or Ubuntu based systems: apt-get purge libcpanel-json-xs-perl.
    • For CentOS based systems: yum remove perl-Cpanel-JSON-XS.
    • Directly from CPAN: cpanm --uninstall Cpanel::JSON::XS.
  • Restart the Apache web server process.

What if Cpanel/JSON/XS.pm is still needed?

If for some reason a customer installation requires Cpanel::JSON::XS for other purposes not related with Enswitch, more tests will be needed to check the following:

  • If the processes of the Apache web server are adversely affected, like detailed before, by merely having the XS.so file of Cpanel::JSON::XS in the filesystem.
  • If having CryptX > 0.072 is enough to avoid the mentioned segmentation faults, even if Cpanel::JSON::XS is installed with its XS.so file.