DEFINITIVE TIMEOUT SOLUTION: FIXING ‘CONTEXT CANCELED’ IN CYBERPANEL (LITESPEED/DOCKER)
PROBLEM
The error Incoming request ended abruptly: context canceled (or 503/504 Gateway Timeout) appears in the Docker or LiteSpeed/CyberPanel log, even after increasing the PHP max_execution_time.
This happens because a proxy component or LiteSpeed itself (acting as a proxy for PHP) is closing the connection before the PHP script can finish, disregarding the high limit configured in php.ini.
SOLUTION
The solution consists of ensuring that PHP has the correct execution and termination time and, crucially, that LiteSpeed (in its Virtual Host) is instructed to wait for PHP for the same period.
STEP 1: php.ini Adjustment (Advanced Configuration)
-
Access CyberPanel: PHP $\rightarrow$ Edit PHP Configs $\rightarrow$ Advanced.
-
Select your site’s PHP version (e.g., PHP 8.3).
-
Ensure that the
max_execution_timeandmax_input_timevalues are set to the desired value (e.g.,300). -
Add the crucial directive
request_terminate_timeoutwith a slightly higher value.
Settings to apply in php.ini:
Ini, TOML
; Maximum time a script can run
max_execution_time = 300
; Maximum time for reading the request (input)
max_input_time = 300
; Maximum time PHP-FPM should wait before terminating the process
request_terminate_timeout = 301
- Save changes and Restart PHP (
PHP$\rightarrow$Restart PHP).
STEP 2: LiteSpeed Virtual Host Adjustment (SSH)
The context canceled error is usually resolved by instructing LiteSpeed (the frontend) to wait longer for the External Application (PHP).
-
Access the server via SSH.
-
Edit your Virtual Host (VH) configuration file, located at:
Bash
sudo nano /usr/local/lsws/conf/vhosts/YOUR_DOMAIN/vhconf.conf(Replace
YOUR_DOMAINwith the actual name of your Virtual Host.) -
Locate the
extprocessorsection (in our case, it wasmerca4425) and adjust the timeout directives to a high value (e.g.,600seconds), ensuring they are greater than the PHP limit (301s).
Settings to apply in vhconf.conf:
Snippet de código
extprocessor merca4425 {
type lsapi
# ... (other configurations)
# Maximum time to initiate connection with PHP
initTimeout 600
# Time LiteSpeed waits for a connection retry attempt (CRITICAL)
retryTimeout 600
# ... (other configurations)
}
-
Save the file and Restart OpenLiteSpeed:
Bash
sudo /usr/local/lsws/bin/lswsctrl restart
RESULT
With these synchronized configurations across all layers (PHP and LiteSpeed), the error message Incoming request ended abruptly: context canceled is eliminated, and long-running scripts can be completed successfully within the new defined time limit.