{"record":{"id":"91991d46bbd7aff3","repo":"mongodb/laravel-mongodb","slug":"atlas-search-index-operation-time-out-after-s-seconds","errorCode":null,"errorMessage":"Atlas search index operation time out after %s seconds","messagePattern":"Atlas search index operation time out after (.+?) seconds","errorType":"exception","errorClass":"MongoDBRuntimeException","httpStatus":null,"severity":"warning","filePath":"src/Scout/ScoutEngine.php","lineNumber":565,"sourceCode":"    }\n\n    /**\n     * Wait for the callback to return true, use it for asynchronous\n     * Atlas Search index management operations.\n     */\n    private function wait(Closure $callback): void\n    {\n        // Fallback to time() if hrtime() is not supported\n        $timeout = (hrtime()[0] ?? time()) + self::WAIT_TIMEOUT_SEC;\n        while ((hrtime()[0] ?? time()) < $timeout) {\n            if ($callback()) {\n                return;\n            }\n\n            sleep(1);\n        }\n\n        throw new MongoDBRuntimeException(sprintf('Atlas search index operation time out after %s seconds', self::WAIT_TIMEOUT_SEC));\n    }\n}\n","sourceCodeStart":547,"sourceCodeEnd":568,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Scout/ScoutEngine.php#L547-L568","documentation":"After issuing createSearchIndexes, the engine polls until the index becomes queryable, sleeping 1s per iteration up to WAIT_TIMEOUT_SEC. If the index is still not ready after the timeout, a MongoDBRuntimeException is thrown reporting the number of seconds waited.","triggerScenarios":"Calling createIndex() on a slow Atlas cluster where the search index stays in a non-buildable/pending state beyond WAIT_TIMEOUT_SEC (index build stuck, large initial sync, Atlas maintenance, network latency).","commonSituations":"Free/shared Atlas tiers with slow index provisioning; transient Atlas control-plane issues; very large collections during first-time index builds.","solutions":["Retry createIndex() after the Atlas cluster finishes provisioning the index","Verify the index status in the Atlas UI (Atlas Search index should reach 'Active')","Increase patience/retry around deployment scripts that call createIndex during migrations","Check Atlas alerts and cluster health; escalate or recreate the index if it is stuck in a failed state"],"exampleFix":"// before\n$engine->createIndex('search_index'); // may throw on slow clusters\n// after\ntry {\n    $engine->createIndex('search_index');\n} catch (\\MongoDB\\Driver\\Exception\\RuntimeException $e) {\n    sleep(30);\n    $engine->createIndex('search_index'); // retry after Atlas provisioning\n}","handlingStrategy":"retry","validationCode":"// Pre-check cluster reachability before createIndex\n$engine->getIndexClient()->listSearchIndexes(); // throws early on connectivity problems","typeGuard":null,"tryCatchPattern":"$retries = 3;\nwhile (true) {\n    try { $engine->createIndex('search_index'); break; }\n    catch (\\MongoDB\\Driver\\Exception\\RuntimeException $e) {\n        if (str_contains($e->getMessage(), 'time out after') && --$retries > 0) { sleep(30); continue; }\n        throw $e;\n    }\n}","preventionTips":["Provision Atlas Search indexes outside deployment-critical paths (CI/one-off jobs)","Monitor Atlas index build status before running migrations that call createIndex","Allow extra time on free/shared tiers where provisioning is slow","Alert on Atlas Search index state changes to catch stuck builds early"],"tags":["php","laravel-scout","atlas-search","timeout"],"backgroundTag":"request-timeout","analyzedSha":"0634653039468ceb0268a69192bdac64469ed043","analyzedAt":"2026-09-15T02:56:37.067Z","contentChangedAt":"2026-09-15T02:56:37.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}