Page MenuHomePhabricator

[Log noise] "Prefix search request was longer than the maximum allowed length."
Closed, ResolvedPublic3 Estimated Story PointsPRODUCTION ERROR



MediaWiki version: 1.36.0-wmf.32

Prefix search request was longer than the maximum allowed length.
from /srv/mediawiki/php-1.36.0-wmf.32/includes/api/ApiUsageException.php(71)
#0 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/Query/QueryBuilderTraits.php(25): ApiUsageException::newWithMessage(NULL, array, string, array, integer)
#1 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/Query/CompSuggestQueryBuilder.php(87): CirrusSearch\Query\CompSuggestQueryBuilder->checkTitleSearchRequestLength(string)
#2 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/CompletionSuggester.php(309): CirrusSearch\Query\CompSuggestQueryBuilder->build(string, array)
#3 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/CompletionSuggester.php(186): CirrusSearch\CompletionSuggester->getSuggestSearchRequest(string, array)
#4 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/CirrusSearch.php(360): CirrusSearch\CompletionSuggester->suggest(string, array)
#5 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/CirrusSearch.php(441): CirrusSearch\CirrusSearch->getSuggestions(string, array, CirrusSearch\SearchConfig)
#6 /srv/mediawiki/php-1.36.0-wmf.32/includes/search/SearchEngine.php(556): CirrusSearch\CirrusSearch->completionSearchBackend(string)
#7 /srv/mediawiki/php-1.36.0-wmf.32/includes/search/SearchEngine.php(602): SearchEngine->completionSearchBackendOverfetch(string)
#8 /srv/mediawiki/php-1.36.0-wmf.32/extensions/CirrusSearch/includes/CirrusSearch.php(452): SearchEngine->completionSearch(string)
#9 /srv/mediawiki/php-1.36.0-wmf.32/includes/Rest/Handler/SearchHandler.php(156): CirrusSearch\CirrusSearch->completionSearchWithVariants(string)
#10 /srv/mediawiki/php-1.36.0-wmf.32/includes/Rest/Handler/SearchHandler.php(311): MediaWiki\Rest\Handler\SearchHandler->doSearch(CirrusSearch\CirrusSearch)
#11 /srv/mediawiki/php-1.36.0-wmf.32/includes/Rest/Router.php(395): MediaWiki\Rest\Handler\SearchHandler->execute()
#12 /srv/mediawiki/php-1.36.0-wmf.32/includes/Rest/Router.php(322): MediaWiki\Rest\Router->executeHandler(MediaWiki\Rest\Handler\SearchHandler)
#13 /srv/mediawiki/php-1.36.0-wmf.32/includes/Rest/EntryPoint.php(165): MediaWiki\Rest\Router->execute(MediaWiki\Rest\RequestFromGlobals)
#14 /srv/mediawiki/php-1.36.0-wmf.32/includes/Rest/EntryPoint.php(130): MediaWiki\Rest\EntryPoint->execute()
#15 /srv/mediawiki/php-1.36.0-wmf.32/rest.php(31): MediaWiki\Rest\EntryPoint::main()
#16 /srv/mediawiki/w/rest.php(3): require(string)
#17 {main}


User can trigger log spam by sending large search strings.



Request ID
Request URL

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The limit is 255 (using mb_strlen), not sure what to do instead.
Having a user visible exception instead to show an error message. But api part needs some error reporting as well.

		$requestLength = mb_strlen( $term );
		if ( $requestLength > CirrusSearch::MAX_TITLE_SEARCH ) {
			// TODO: stop using ApiUsageException we are not even sure that we are in an API call
			throw ApiUsageException::newWithMessage(
				[ 'apierror-cirrus-requesttoolong', $requestLength, CirrusSearch::MAX_TITLE_SEARCH ],

An ApiUsageException generally doesn't make it into the error log... why is this one logged?

Oh I see - ApiUsageException is handled by ApiMain, but the request in question is coming in an REST endpoint. Rest\Router and Rest\Handler don't have handling for this kind of exception, and probably should not.

I think the correct thing to do here is to throw a different exception, and convert it as appropriate in the code that implements search for the different API endpoints.

Alternatively, the API handlers (action API module and REST API handler) could apply the length check themselves, so they have control over the error handling. The "deeper" code could throw an InvalidArgumentException, but hopefully we'd never trigger that.

@daniel See also ErrorPageError (and ILocalizedException) which are a similar abstraction used by Actions and Special pages. Seems like maybe there's a reasonable way we can minimally implement ILocalizedException such that we don't need a ErrorPageError, ApiUsageException and now REST-specific implementation, but just the general one and rendered into the appropiate response by the entry point catch handler (where the rendering would not itself be an Exception subclass).

As I start the train for 1.36.0-wmf.34 (T274938), this continues at a rate of 100-200 an hour. While it's filtered on the mw-new-errors dashboard, it's not great for using the mediawiki-errors dashboard or logspam-watch. Deployers would appreciate a fix.

While pondering a fix, i wonder if cirrussearch really even needs to throw an exception here. Page titles are well documented as limited to 255 bytes. In other cases where we receive queries with no possible answer we simply return no results as the correct answer. That seems sane here, and if we want to provide a better UX in this narrow case (i suspect these are mostly automated and it helps the rare human) that can be implemented in a sensible layer.

Change 670329 had a related patch set uploaded (by Ebernhardson; owner: Ebernhardson):
[mediawiki/extensions/CirrusSearch@master] Return no results for over-length title searches

Krinkle renamed this task from Unnecessary error log entry: Prefix search request was longer than the maximum allowed length. to [Log noise] "Prefix search request was longer than the maximum allowed length.".Mar 10 2021, 7:42 PM
Krinkle updated the task description. (Show Details)
Krinkle edited Stack Trace. (Show Details)

Change 670329 merged by jenkins-bot:
[mediawiki/extensions/CirrusSearch@master] Return no results for over-length title searches

Much appreciation for this change!