Magento 2.0 uses Oyejorge LESS processor to compile stylesheets from Less to CSS.
Today I encountered a bug in Oyejorge LESS processor which leads to segmentation fault in PHP interpreter.
Google Chrome browser returns ERR_CONNECTION_RESET
error code.
wget
return connection reset by peer
message.
I fixed this bug, but I want to save the way to fix similar bugs for future.
File: vendor/oyejorge/less.php/lib/Less/Tree/Ruleset.php
Method: evalImports
Add temporary logging to it:
function evalImports($env) {
static $deepLevel = -1;
/** @var Magento\Framework\Logger\Monolog $logger */
static $logger = \Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface');
$deepLevel++;
$logger->debug(str_repeat("\t", $deepLevel) . 'evalImports BEGIN');
$rules_len = count($this->rules);
for($i=0; $i < $rules_len; $i++){
$rule = $this->rules[$i];
if( $rule instanceof Less_Tree_Import ) {
$logger->debug(str_repeat("\t", $deepLevel) . 'BEGIN RULE: ' . $rule->path->value);
$deepLevel++;
$rules = $rule->compile($env);
if (is_array($rules)) {
array_splice(
$this->rules,
$i,
1,
$rules
);
$temp_count = count($rules) - 1;
$i += $temp_count;
$rules_len += $temp_count;
}
else {
array_splice(
$this->rules,
$i,
1,
array($rules)
);
}
$this->resetCache();
$deepLevel--;
$logger->debug(str_repeat("\t", $deepLevel) . 'END RULE: ' . $rule->path->value);
}
}
$logger->debug(str_repeat("\t", $deepLevel) . 'evalImports END');
$deepLevel--;
}
Then execute the problem request (styles-m.css
in my case):
wget -t 1 http://<your domain>/pub/static/frontend/Magento/luma/en_US/css/styles-m.css
And you will see in var/log/debug.log
what the Less rule breaks Oyejorge LESS processor.