Bobcares

How to fix “Error: unable to read what child say: bad file descriptor”

by | Dec 2, 2018

Website errors can be frustrating, especially if they are cryptic, like “Error: unable to read what child say: bad file descriptor“.

You know that there is an error but where?

Here at Bobcares, we help website owners to resolve such complex errors as part of our Support Engineers services.

Today, let’s see the top 3 reasons for this error and how we fix them.

 

What is “Error: unable to read what child say: bad file descriptor”?

It’s true that Nginx and PHP-FPM combo is a better option for handling a large number of requests.

This is because, Nginx requires significantly less memory per connection, and PHP-FPM dramatically speeds up the performance of your PHP environment.

But, if you have a busy server, sometimes PHP-PFM may crash out.

As a result, users experience website errors, like ‘502 bad gateway’ or ‘503 Service temporary unavailable’ in their web browsers.

Here, we check the error logs(/var/log/phpX-fpm.log or /var/log/plesk-phpXX-fpm/error.log, where X is the PHP version) to get the detailed error message.

For instance, in Plesk servers, the error looks like this:

ERROR: unable to read what child say: Bad file descriptor (9)

 

Now, let’s discuss the 2 main causes of this error and how our Support Engineers fix them.

 

“Error: unable to read what child say: bad file descriptor” – Causes & Fixes!

In our experience handling website issues, we found 3 main reasons for this “Error: unable to read what child say: bad file descriptor”.

 

1) Service downtime

Sometimes, unexpected service crashes can lead to this error.

PHP-FPM is an alternate FastCGI service that allows a website to handle heavy loads.

But, this service may fail due to traffic spikes, resource limits, disk errors, DDOS attack, etc.

 

How we fix?

Firstly, we check the status of php-fpm service.

For instance, in Plesk servers, we check the service status as below. Here X is the PHP version.

service plesk-phpXX-fpm status

 

If there is a failed or unresponsive service, our primary focus is to figure out the problem and fix the service.

This is done with the help of application, service and website logs.

 

2) PHP-FPM configuration issues

PHP-FPM has a lot of configuration parameters which determine the way it performs.

These parameters have to be determined based on the available server resources like RAM, CPU, etc.

The php-fpm configuration file /etc/php-fpm.conf or /etc/php-fpm.d/[domain.com].conf looks like this:

pm = ondemand
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 150

 

But, in the below scenarios, this default setting doesn’t work and php-fpm reaches max_children.

  • Lot of concurrent visitors to the website.
  • Buggy PHP scripts in the website.
  • Slow execution of PHP scripts due to server resources.

 

Result is “Error: unable to read what child say: bad file descriptor”.

 

How we fix?

The solution is to tweak these PHP-FPM settings based on available server resources. Otherwise, the server may crash.

Therefore, our Support Engineers first check available server resources, website traffic, website contents and then fine tune these values.

Also, in a server with multiple services, all of them are taken into account while tuning these parameters.

Let’s see how we tweak these values in a Plesk server.

 

a) First, we create/edit the custom php.ini file in the domain config directory “/var/www/vhosts/system/domain.com/conf/“.

b) Further, we tweak the following php-fpm parameters and add them to the above file.

pm.max_children = 40
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 8
pm.max_requests = 600

 

c) Now, we update the new PHP settings in PHP configuration file with the following command:

/usr/local/psa/bin/php_settings -u

 

d) Then, recompile the domain settings with the following command:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com

 

e) Finally, restart the php-fpm service with the following command:

service plesk-phpXX-fpm restart

 

3) PHP bug

PHP-FPM has worker processes that handles the PHP requests.

We’ve seen users enable catch_workers_output in the PHP-FPM configuration to allow error logging for these worker processes.

Sometimes, it conflicts with the PHP versions and leads to “Error: unable to read what child say: bad file descriptor”.

 

How we fix?

PHP has officially declared this as a bug, affecting versions 5.3.27, 5.4.17, 5.5.1.

So, first we try to upgrade the PHP version of the website to PHP 7, as it makes the website faster and secure.

However, sometimes the website settings may not be compatible with the new PHP version.

Therefore, before upgrading, we first check the compatibility of the website with the new PHP version.

If upgrade is not possible, we’ll download and apply the patch “fpm-race-condition.patch” released by PHP.

 

Conclusion

In short, Error: unable to read what child say: bad file descriptor can occur due to service downtime, php-fpm configuration issues, etc. Today, we’ve discussed the top 3 reasons for this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF