{"record":{"id":"e84c1e5d93983114","repo":"laravel/framework","slug":"timeout-must-be-greater-than-zero","errorCode":null,"errorMessage":"Timeout must be greater than zero.","messagePattern":"Timeout must be greater than zero\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":3381,"sourceCode":"     * @return $this\n     */\n    public function sharedLock()\n    {\n        return $this->lock(false);\n    }\n\n    /**\n     * Set a query execution timeout in seconds.\n     *\n     * @param  int|null  $seconds\n     * @return $this\n     *\n     * @throws InvalidArgumentException\n     */\n    public function timeout(?int $seconds): static\n    {\n        if ($seconds !== null && $seconds <= 0) {\n            throw new InvalidArgumentException('Timeout must be greater than zero.');\n        }\n\n        $this->timeout = $seconds;\n\n        return $this;\n    }\n\n    /**\n     * Register a closure to be invoked before the query is executed.\n     *\n     * @return $this\n     */\n    public function beforeQuery(callable $callback)\n    {\n        $this->beforeQueryCallbacks[] = $callback;\n\n        return $this;\n    }","sourceCodeStart":3363,"sourceCodeEnd":3399,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L3363-L3399","documentation":"timeout() sets a per-query execution timeout. A null argument means 'no timeout', and any positive integer is accepted, but a non-positive integer (0 or negative) is meaningless as a timeout and is rejected with InvalidArgumentException before it could produce surprising SQL.","triggerScenarios":"->timeout(0), ->timeout(-5), or passing a computed value (e.g. config('query.timeout') configured to 0) when the engine cannot honour a zero/negative duration.","commonSituations":"Reading the timeout from config/env and forgetting to default it; passing a configurable value that an operator set to 0 thinking it disables the limit (use null instead); math that yields a negative number.","solutions":["Pass null to explicitly disable the timeout instead of 0.","Coerce incoming config: $seconds = $cfg > 0 ? $cfg : null.","Fix the config/env value to a positive integer."],"exampleFix":"// before\n->timeout(config('database.options.timeout', 0))\n\n// after\n->timeout(config('database.options.timeout'))  // null when unset","handlingStrategy":"validation","validationCode":"$seconds = $cfg > 0 ? (int) $cfg : null;\n$query->timeout($seconds);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use null to mean 'no timeout', never 0.","Coerce config values: keep only positive integers, else null.","Document the meaning of null vs positive int in the config file."],"tags":["query-builder","timeout","database","config"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}