{"record":{"id":"2e050ca481537815","repo":"symfony/process","slug":"the-timeout-value-must-be-a-valid-positive-integer-or-float","errorCode":null,"errorMessage":"The timeout value must be a valid positive integer or float number.","messagePattern":"The timeout value must be a valid positive integer or float number\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Process.php","lineNumber":1432,"sourceCode":"\n        $this->requireProcessIsStarted($caller);\n\n        $this->updateStatus($blocking);\n    }\n\n    /**\n     * Validates and returns the filtered timeout.\n     *\n     * @throws InvalidArgumentException if the given timeout is a negative number\n     */\n    private function validateTimeout(?float $timeout): ?float\n    {\n        $timeout = (float) $timeout;\n\n        if (0.0 === $timeout) {\n            $timeout = null;\n        } elseif ($timeout < 0) {\n            throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');\n        }\n\n        return $timeout;\n    }\n\n    /**\n     * Reads pipes, executes callback.\n     *\n     * @param bool $blocking Whether to use blocking calls or not\n     * @param bool $close    Whether to close file handles or not\n     */\n    private function readPipes(bool $blocking, bool $close): void\n    {\n        $result = $this->processPipes->readAndWrite($blocking, $close);\n\n        $callback = $this->callback;\n        foreach ($result as $type => $data) {\n            if (3 !== $type) {","sourceCodeStart":1414,"sourceCodeEnd":1450,"githubUrl":"https://github.com/symfony/process/blob/99b85026db14a68f02c6f3eeb01a1170ca25c491/Process.php#L1414-L1450","documentation":"validateTimeout() casts the given value to float and rejects negative numbers (and NaN via comparison semantics) with an InvalidArgumentException. Zero is treated as 'no timeout' (null), but anything negative is invalid.","triggerScenarios":"setTimeout(-1), setIdleTimeout(-5), passing a non-numeric string like '30s' which casts to 0.0 silently, or passing an array/object that cannot be cast to float.","commonSituations":"Config values with units ('30s', '5m') passed as strings, negative values from misparsed config, null confusion expecting an exception-free path.","solutions":["Pass a positive numeric value (int/float) in seconds","Parse duration strings yourself before passing (e.g. convert '30s' to 30.0)","Use 0 or null to disable the timeout instead of a negative number"],"exampleFix":"// before\n$process->setTimeout('30s');\n// after\n$process->setTimeout(30.0);","handlingStrategy":"validation","validationCode":"$t = (float) $timeout;\nif ($t < 0 || is_nan($t)) { throw new InvalidArgumentException('timeout must be >= 0'); }\n$process->setTimeout($t);","typeGuard":null,"tryCatchPattern":"try { $process->setTimeout($timeout); } catch (InvalidArgumentException $e) { /* sanitize and retry */ }","preventionTips":["Parse duration strings ('30s') to seconds before passing","Reject negative timeout values in your config layer","Use 0 or null explicitly for 'no timeout'"],"tags":["php","process","timeout","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"99b85026db14a68f02c6f3eeb01a1170ca25c491","analyzedAt":"2026-09-14T11:23:33.683Z","contentChangedAt":"2026-09-14T11:23:33.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}