Query overheated error when viewing Home if user can't see all repos

Observed Behavior:
A user reported that the Phabricator home page is totally broken and prints the following error:

Query (of class "PhabricatorRepositoryQuery") overheated: examined more than 60 raw rows without finding 6 visible object.

This corresponds to the following traceback from the Apache error log:

[2019-03-26 14:49:08] EXCEPTION: (Exception) Query (of class "PhabricatorRepositoryQuery") overheated: examined more than 60 raw rows without finding 6 visible objects. at [<phabricator>/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php:339]
arcanist(), phabricator(custom=5), phutil()
  #0 <#2> PhabricatorPolicyAwareQuery::execute() called at [<phabricator>/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php:355]
  #1 <#2> PhabricatorCursorPagedPolicyAwareQuery::executeWithCursorPager(AphrontCursorPagerView) called at [<phabricator>/src/applications/search/engine/PhabricatorApplicationSearchEngine.php:1025]
  #2 <#2> PhabricatorApplicationSearchEngine::executeQuery(PhabricatorRepositoryQuery, AphrontCursorPagerView) called at [<phabricator>/src/applications/home/view/PHUIHomeView.php:216]
  #3 <#2> PHUIHomeView::buildRepositoryPanel() called at [<phabricator>/src/applications/home/view/PHUIHomeView.php:42]
  #4 <#2> PHUIHomeView::getTagContent() called at [<phabricator>/src/view/AphrontTagView.php:101]
  #5 <#2> AphrontTagView::render() called at [<phabricator>/src/view/AphrontView.php:222]
  #6 <#2> AphrontView::producePhutilSafeHTML() called at [<phutil>/src/markup/render.php:111]
  #7 <#2> phutil_escape_html(PHUIHomeView) called at [<phutil>/src/markup/render.php:135]
  #8 <#2> phutil_escape_html(array) called at [<phutil>/src/markup/render.php:167]
  #9 <#2> phutil_implode_html(string, array) called at [<phabricator>/src/view/page/PhabricatorBarePageView.php:58]
  #10 <#2> PhabricatorBarePageView::willRenderPage() called at [<phabricator>/src/view/page/PhabricatorStandardPageView.php:211]
  #11 <#2> PhabricatorStandardPageView::willRenderPage() called at [<phabricator>/src/view/page/AphrontPageView.php:46]
  #12 <#2> AphrontPageView::render() called at [<phabricator>/src/view/page/PhabricatorStandardPageView.php:890]
  #13 <#2> PhabricatorStandardPageView::produceAphrontResponse() called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:715]
  #14 <#2> AphrontApplicationConfiguration::produceResponse(AphrontRequest, PhabricatorStandardPageView) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:301]
  #15 phlog(Exception) called at [<phabricator>/src/aphront/handler/PhabricatorDefaultRequestExceptionHandler.php:41]
  #16 PhabricatorDefaultRequestExceptionHandler::handleRequestThrowable(AphrontRequest, Exception) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:744]
  #17 AphrontApplicationConfiguration::handleThrowable(Exception) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:333]
  #18 AphrontApplicationConfiguration::processRequest(AphrontRequest, PhutilDeferredLog, AphrontPHPHTTPSink, MultimeterControl) called at [<phabricator>/src/aphront/configuration/AphrontApplicationConfiguration.php:209]
  #19 AphrontApplicationConfiguration::runHTTPRequest(AphrontPHPHTTPSink) called at [<phabricator>/webroot/index.php:35]

This appears to be new between 2019 Week 10 and 2019 Week 12

This does not occur for me and I suspect it’s because we have several hundred repositories and this user can see some (but not all) of them. It doesn’t appear to occur for users who can’t see any repositories, and it doesn’t occur for users (like myself) who can see most of the repositories.

Expected Behavior:
Not crashing on home

Phabricator Version:
Internal fork last branched off of stable at 3d481fb75772ac6df23c71c11607734607ee741c (2019 Week 12)

Reproduction Steps:
none yet

for now I have worked around this with the following patch (which is stupid):

--- a/src/applications/home/view/PHUIHomeView.php
+++ b/src/applications/home/view/PHUIHomeView.php
@@ -38,7 +38,7 @@ final class PHUIHomeView

     $repository_panel = null;
-    if ($has_diffusion) {
+    if (false) {
       $repository_panel = $this->buildRepositoryPanel();

I suspect the actual fix will be to enable returnPartialResultsOnOverheat for this query…

This was almost certainly “broken” by https://secure.phabricator.com/D20294, although the old behavior was to silently return no results, which is also “broken” for some definition of broken, but probably less broken than “fatal the whole page”.

The ideal pathway here is to replace the hard-coded default homepage with a panel-based homepage, make panels recover gracefully when they overheat if they don’t already, and then possibly tweak the overheat behavior since overheating after examining 60 rows is a little silly, even though this user is not likely to find 6 results even if we examine the more normal 1,000 rows. Still, we could reasonably try a little harder when the limit is very low, since the cost isn’t prohibitive and overheating is somewhat technical/confusing.

A workaround is probably to replace the default homepage with a dashboard page, but this is somewhat obscure.

This dovetails with some other stuff in the pipeline so I’ll take a look at fixing it correctly tomorrowish. You could “mostly safely” just comment out this exception in PhabricatorPolicyAwareQuery as a workaround. This is technically “unsafe” but it’s how everything has worked for along time without real issues, and likely safe for a few days until the next release.

Still under review, but:

http://secure.phabricator.com/D20333 should provide a minimal fix for this, containing the exception to the panel.

https://secure.phabricator.com/D20335 refines the behavior of overheated panels.