{"record":{"id":"89e247e7511c17f5","repo":"apache/kafka","slug":"buffer-underflow-while-parsing-response-for-reques","errorCode":null,"errorMessage":"Buffer underflow while parsing response for request with header {}","messagePattern":"Buffer underflow while parsing response for request with header (.+?)","errorType":"exception","errorClass":"SchemaException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/NetworkClient.java","lineNumber":921,"sourceCode":"     * <p>\n     * If bootstrap is disabled or already complete, throw IllegalStateException.\n     * If bootstrap is enabled but not yet complete, return an empty {@link LeastLoadedNode}\n     * so that the caller can continue polling while DNS resolution finishes.\n     */\n    private LeastLoadedNode handleEmptyNodeList() {\n        if (bootstrapConfiguration == BootstrapConfiguration.DISABLED || metadataUpdater.isBootstrapped()) {\n            throw new IllegalStateException(\"There are no nodes in the Kafka cluster\");\n        }\n\n        log.debug(\"No nodes available yet, still in bootstrap phase\");\n        return new LeastLoadedNode(null, false);\n    }\n\n    public static AbstractResponse parseResponse(ByteBuffer responseBuffer, RequestHeader requestHeader) {\n        try {\n            return AbstractResponse.parseResponse(responseBuffer, requestHeader);\n        } catch (BufferUnderflowException e) {\n            throw new SchemaException(\"Buffer underflow while parsing response for request with header \" + requestHeader, e);\n        } catch (CorrelationIdMismatchException e) {\n            if (SaslClientAuthenticator.isReserved(requestHeader.correlationId())\n                && !SaslClientAuthenticator.isReserved(e.responseCorrelationId()))\n                throw new SchemaException(\"The response is unrelated to Sasl request since its correlation id is \"\n                    + e.responseCorrelationId() + \" and the reserved range for Sasl request is [ \"\n                    + SaslClientAuthenticator.MIN_RESERVED_CORRELATION_ID + \",\"\n                    + SaslClientAuthenticator.MAX_RESERVED_CORRELATION_ID + \"]\");\n            else {\n                throw e;\n            }\n        }\n    }\n\n    /**\n     * Post process disconnection of a node\n     *\n     * @param responses The list of responses to update\n     * @param nodeId Id of the node to be disconnected","sourceCodeStart":903,"sourceCodeEnd":939,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/NetworkClient.java#L903-L939","documentation":"Thrown by NetworkClient.parseResponse() when AbstractResponse.parseResponse encounters a BufferUnderflowException — the response ByteBuffer does not contain enough bytes to satisfy the expected schema for the given request header. Wrapped in a SchemaException to indicate wire-protocol-level corruption.","triggerScenarios":"A response arrives whose byte length is shorter than the schema demands for the API key/version in the request header. Caused by truncated network reads, mismatched protocol versions between client and broker, or a malformed/corrupt response payload.","commonSituations":"Client/broker version skew where the broker sends a response in an older/newer format than expected, network-layer corruption or MTU truncation, a buggy or non-Kafka server responding on the Kafka port, or a partially-written response due to connection teardown.","solutions":["Verify client and broker Kafka versions are compatible (check supported API version ranges).","Check for network-level issues: MTU mismatches, proxies, or load balancers truncating large responses.","Ensure the endpoint is actually a Kafka broker and not a misrouted service.","Enable DEBUG/TRACE logging on org.apache.kafka.clients to inspect the request header and response size."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    NetworkClient.parseResponse(buf, header);\n} catch (SchemaException e) {\n    // protocol corruption: log header, close connection, do not retry same bytes\n}","preventionTips":["Keep client and broker versions aligned to avoid schema mismatches.","Monitor for BufferUnderflow/SchemaException rates as a network-health signal.","Ensure no proxy truncates Kafka traffic (check MTU/load-balancer config)."],"tags":["network","protocol","serialization"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}