504 Error on WooCommerce Checkout but only when Cron Fires
I am having an issue where, on a site utilizing WooCommerce, handling a few thousand orders per day, users will experience a 504 Timeout error on
wc-ajax=checkout, but only when the WordPress Cron has just started executing (i.e. if the user happens to click the Submit Order button at 0:01-0:04 seconds after the cron job starts). The user’s request times out 60 seconds later per our Apache configuration.
The order actually goes through successfully to the payment gateway (Authorize.NET) and the customer receives an email receipt, but the checkout screen shows no error once the mask disappears so the customer clicks "Submit Order" again and this results in duplicate orders.
This is an example of the error but that’s about all I get that is helpful.
[Sat Nov 28 15:41:04 2020] [proxy_fcgi:error] [pid 30570:tid 140163472602880] (70007)The timeout specified has expired: [client 220.127.116.11:36056] AH01075: Error dispatching request to : (polling), referer https://example.com/checkout
I have added
define('DISABLE_WP_CRON', true) and have our Cron running once every five minutes.
What I have tried/checked:
I went though each process listed in
wp cron event listand ran them manually via the CLI and did not notice any processes that took exceptionally long (the max was 0.4s — most were far shorter).
I have tried increasing the number of PHP-FPM Processes from 5 to 25 as there is plenty of CPU and RAM capacity available on the server, but this doesn’t seem to make much of a difference, nor do I see evidence of a spike when the cron runs.
pm = ondemand pm.max_children = 25 pm.max_requests = 200
Most traffic is offloaded to Cloudflare so for the most part, the server is handling admin tasks, the cart, checkout & cron.
My guess is that for those particular seconds, the cron and checkout are competing for resources and this the cause of the issue though I don’t understand why, the user’s request would run for a minute an then timeout or why increasing the number of children doesn’t seem to make much of
- Does anyone have any other good ideas on how to debug the issue?
- Is there any way to somehow limit the resources that the cron uses or perhaps a better way than simply hitting
https://example.com/wp-cron.phpvia an HTTP request