{"record":{"id":"1954cf205a5144ae","repo":"apache/kafka","slug":"timeout-needs-to-be-greater-than-0","errorCode":null,"errorMessage":"Timeout needs to be greater than 0","messagePattern":"Timeout needs to be greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/NetworkClientUtils.java","lineNumber":61,"sourceCode":"        client.poll(0, currentTime);\n        return client.isReady(node, currentTime);\n    }\n\n    /**\n     * Invokes `client.poll` to discard pending disconnects, followed by `client.ready` and 0 or more `client.poll`\n     * invocations until the connection to `node` is ready, the timeoutMs expires or the connection fails.\n     *\n     * It returns `true` if the call completes normally or `false` if the timeoutMs expires. If the connection fails,\n     * an `IOException` is thrown instead. Note that if the `NetworkClient` has been configured with a positive\n     * connection timeoutMs, it is possible for this method to raise an `IOException` for a previous connection which\n     * has recently disconnected. If authentication to the node fails, an `AuthenticationException` is thrown.\n     *\n     * This method is useful for implementing blocking behaviour on top of the non-blocking `NetworkClient`, use it with\n     * care.\n     */\n    public static boolean awaitReady(KafkaClient client, Node node, Time time, long timeoutMs) throws IOException {\n        if (timeoutMs < 0) {\n            throw new IllegalArgumentException(\"Timeout needs to be greater than 0\");\n        }\n        long startTime = time.milliseconds();\n\n        if (isReady(client, node, startTime) ||  client.ready(node, startTime))\n            return true;\n\n        long attemptStartTime = time.milliseconds();\n        while (!client.isReady(node, attemptStartTime) && attemptStartTime - startTime < timeoutMs) {\n            if (client.connectionFailed(node)) {\n                throw new IOException(\"Connection to \" + node + \" failed.\");\n            }\n            long pollTimeout = timeoutMs - (attemptStartTime - startTime); // initialize in this order to avoid overflow\n\n            // If the network client is waiting to send data for some reason (eg. throttling or retry backoff),\n            // polling longer than that is potentially dangerous as the producer will not attempt to send\n            // any pending requests.\n            long waitingTime = client.pollDelayMs(node, startTime);\n            if (waitingTime > 0 && pollTimeout > waitingTime) {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/NetworkClientUtils.java#L43-L79","documentation":"Thrown by NetworkClientUtils.awaitReady() when timeoutMs is negative. Note the message says 'greater than 0' but the guard is timeoutMs < 0, so a value of exactly 0 is permitted. This is a pre-condition check on the supplied timeout before entering the connection-wait loop.","triggerScenarios":"Calling awaitReady(client, node, time, timeoutMs) with a negative timeoutMs value. This typically comes from arithmetic that underflows or a misconfigured timeout setting.","commonSituations":"Deadline calculations that subtract too much elapsed time and go negative, misconfigured request.timeout.ms or related timeout properties, or programmatic callers computing remaining time incorrectly.","solutions":["Ensure the timeoutMs passed to awaitReady is >= 0; clamp negative computed values to 0.","Check deadline arithmetic: compute remaining as max(0, deadline - now) to avoid underflow.","Validate configuration values for timeout properties are non-negative."],"exampleFix":"// before\nlong remaining = deadline - time.milliseconds();\nawaitReady(client, node, time, remaining); // may be negative\n\n// after\nlong remaining = Math.max(0, deadline - time.milliseconds());\nawaitReady(client, node, time, remaining);","handlingStrategy":"validation","validationCode":"long timeoutMs = Math.max(0, deadline - time.milliseconds());\nNetworkClientUtils.awaitReady(client, node, time, timeoutMs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp all computed timeouts with Math.max(0, ...) before passing in.","Validate configured timeout properties are non-negative at startup.","Compute remaining time as (deadline - now), never (now - deadline)."],"tags":["validation","timeout","config"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}