nextcloud / fulltextsearch_elasticsearch

🔍 Use Elasticsearch to index the content of your Nextcloud
https://apps.nextcloud.com/apps/fulltextsearch_elasticsearch
GNU Affero General Public License v3.0
81 stars 30 forks source link

Unhandled exception during index job #169

Open pelzvieh opened 3 years ago

pelzvieh commented 3 years ago

Running occ fulltextsearch:index aborts with the following exception:

An unhandled exception has been thrown:
TypeError: Argument 2 passed to OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform::getArray() must be of the type array, null given, called in /var/www/nextcloud/extra-apps/fulltextsearch_elasticsearch/lib/Platform/ElasticSearchPlatform.php on line 317 and defined in /var/www/nextcloud/extra-apps/fulltextsearch_elasticsearch/vendor/daita/my-small-php-tools/lib/Traits/TArrayTools.php:252
Stack trace:
#0 /var/www/nextcloud/extra-apps/fulltextsearch_elasticsearch/lib/Platform/ElasticSearchPlatform.php(317): OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform->getArray('error', NULL)
#1 /var/www/nextcloud/extra-apps/fulltextsearch_elasticsearch/lib/Platform/ElasticSearchPlatform.php(287): OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform->parseIndexErrorException(Object(Elasticsearch\Common\Exceptions\BadRequest400Exception))
#2 /var/www/nextcloud/extra-apps/fulltextsearch_elasticsearch/lib/Platform/ElasticSearchPlatform.php(236): OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform->manageIndexErrorException(Object(OCA\Files_FullTextSearch\Model\FilesDocument), Object(Elasticsearch\Common\Exceptions\BadRequest400Exception))
#3 /var/www/nextcloud/extra-apps/fulltextsearch/lib/Service/IndexService.php(375): OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform->indexDocument(Object(OCA\Files_FullTextSearch\Model\FilesDocument))
#4 /var/www/nextcloud/extra-apps/fulltextsearch/lib/Service/IndexService.php(326): OCA\FullTextSearch\Service\IndexService->indexDocument(Object(OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform), Object(OCA\Files_FullTextSearch\Model\FilesDocument))
#5 /var/www/nextcloud/extra-apps/fulltextsearch/lib/Service/IndexService.php(204): OCA\FullTextSearch\Service\IndexService->indexDocuments(Object(OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform), Object(OCA\Files_FullTextSearch\Provider\FilesProvider), Array, Object(OCA\FullTextSearch\Model\IndexOptions))
#6 /var/www/nextcloud/extra-apps/fulltextsearch/lib/Command/Index.php(410): OCA\FullTextSearch\Service\IndexService->indexProviderContentFromUser(Object(OCA\FullTextSearch_Elasticsearch\Platform\ElasticSearchPlatform), Object(OCA\Files_FullTextSearch\Provider\FilesProvider), 'pelzi', Object(OCA\FullTextSearch\Model\IndexOptions))
#7 /var/www/nextcloud/extra-apps/fulltextsearch/lib/Command/Index.php(273): OCA\FullTextSearch\Command\Index->indexProvider(Object(OCA\Files_FullTextSearch\Provider\FilesProvider), Object(OCA\FullTextSearch\Model\IndexOptions))
#8 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\FullTextSearch\Command\Index->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/nextcloud/core/Command/Base.php(169): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(OCA\FullTextSearch\Command\Index), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/nextcloud/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#15 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#16 {main}

Obviously, introducing a check to parseIndexErrorException if the array argument is null, cures the problem, but I have no idea if this is semantically correct.

CharlesCage commented 3 years ago

I think this is the same problem I'm experiencing in #170 .

This is happening here:


        /**
         * @param IIndexDocument $document
         *
         * @return IIndex
         */
        public function indexDocument(IIndexDocument $document): IIndex {

                $document->initHash();

                $index = null;
                try {
                        $result = $this->indexService->indexDocument($this->client, $document);
                        $index = $this->indexService->parseIndexResult($document->getIndex(), $result);

                        $this->updateNewIndexResult(
                                $document->getIndex(), json_encode($result), 'ok',
                                IRunner::RESULT_TYPE_SUCCESS
                        );

                        return $index;
                } catch (Exception $e) {
                        $this->manageIndexErrorException($document, $e);
                }

                try {
                        $result = $this->indexDocumentError($document, $e);
                        $index = $this->indexService->parseIndexResult($document->getIndex(), $result);

                        $this->updateNewIndexResult(
                                $document->getIndex(), json_encode($result), 'ok',
                                IRunner::RESULT_TYPE_WARNING
                        );

                        return $index;
                } catch (Exception $e) {
                        $this->updateNewIndexResult(
                                $document->getIndex(), '', 'fail',
                                IRunner::RESULT_TYPE_FAIL
                        );
                        $this->manageIndexErrorException($document, $e);
                }

                return $document->getIndex();
        }

For whatever reason the first try is catching an exception that's returning null.

CharlesCage commented 3 years ago

FYI, @pelzvieh if you check the comments I made in the linked issue I found a solution for this. You need to increase http.max_content_length in the Elasticsearch config file (usually /etc/elasticsearch/elasticsearch.yml). I'm still concerned that this error could trigger in my setup with a max size limit of 100mb configured in Nextcloud and the default 100mb http.max_content_length in Elasticsearch.