From baab085b322c67877ef9507255d1faf953bb98b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 23 May 2017 14:48:32 +0200 Subject: [PATCH] Parser: Better debugging of lock errors ("Did you call Parser::parse recursively?") Save the backtrace when locking, so that if some code tries locking again, we can print the lock owner's backtrace for easier debugging. Change-Id: I6e352b4aa5e7cb35825a66592f6c066d9e8b95c9 --- includes/parser/Parser.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index ecee0e22d3..11392dea4e 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -245,7 +245,7 @@ class Parser { public $currentRevisionCache; /** - * @var bool Recursive call protection. + * @var bool|string Recursive call protection. * This variable should be treated as if it were private. */ public $mInParse = false; @@ -6073,9 +6073,13 @@ class Parser { protected function lock() { if ( $this->mInParse ) { throw new MWException( "Parser state cleared while parsing. " - . "Did you call Parser::parse recursively?" ); + . "Did you call Parser::parse recursively? Lock is held by: " . $this->mInParse ); } - $this->mInParse = true; + + // Save the backtrace when locking, so that if some code tries locking again, + // we can print the lock owner's backtrace for easier debugging + $e = new Exception; + $this->mInParse = $e->getTraceAsString(); $recursiveCheck = new ScopedCallback( function() { $this->mInParse = false; -- 2.20.1