{"record":{"id":"aa8236da5118431f","repo":"eclipse-vertx/vert.x","slug":"keepalivetimeout-must-be-0","errorCode":null,"errorMessage":"keepAliveTimeout must be >= 0","messagePattern":"keepAliveTimeout must be >= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/Http1ClientConfig.java","lineNumber":96,"sourceCode":"  }\n\n  /**\n   * @return the keep alive timeout value in seconds for HTTP/1.x connections\n   */\n  public Duration getKeepAliveTimeout() {\n    return keepAliveTimeout;\n  }\n\n  /**\n   * <p>Set the keep alive timeout for HTTP/1.1 connections. This value determines how long a connection remains\n   * unused in the pool before being evicted and closed. A timeout of zero or {@code null} means there is no timeout.</p>\n   *\n   * @param keepAliveTimeout the timeout, in seconds\n   * @return a reference to this, so the API can be used fluently\n   */\n  public Http1ClientConfig setKeepAliveTimeout(Duration keepAliveTimeout) {\n    if (keepAliveTimeout != null && (keepAliveTimeout.isNegative())) {\n      throw new IllegalArgumentException(\"keepAliveTimeout must be >= 0\");\n    }\n    this.keepAliveTimeout = keepAliveTimeout;\n    return this;\n  }\n\n  /**\n   * Is pipe-lining enabled on the client\n   *\n   * @return {@code true} if pipe-lining is enabled\n   */\n  public boolean isPipelining() {\n    return pipelining;\n  }\n\n  /**\n   * Set whether pipe-lining is enabled on the client\n   *\n   * @param pipelining {@code true} if enabled","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/Http1ClientConfig.java#L78-L114","documentation":"Http1ClientConfig.setKeepAliveTimeout validates the duration and throws IllegalArgumentException when a non-null value is negative. A null duration is allowed (meaning use the default), but keepAliveTimeout cannot be less than zero seconds.","triggerScenarios":"Passing a negative Duration such as Duration.ofSeconds(-1) to Http1ClientConfig.setKeepAliveTimeout, typically via computed values or misparsed configuration.","commonSituations":"Reading a timeout from config where a sentinel -1 means 'infinite' in another library, subtracting durations that produce a negative result, or unit confusion when building the Duration.","solutions":["Pass a non-negative Duration (e.g. Duration.ofSeconds(30)) or null to use defaults","Clamp or validate configuration-provided values before constructing the Duration","If 'disabled' is intended, use null or an appropriately large positive duration, not a negative one"],"exampleFix":"// before\nconfig.setKeepAliveTimeout(Duration.ofSeconds(-1));\n// after\nconfig.setKeepAliveTimeout(Duration.ofSeconds(30));","handlingStrategy":"validation","validationCode":"Duration t = /* from config */;\nif (t != null && t.isNegative()) {\n  throw new IllegalArgumentException(\"keepAliveTimeout must be >= 0, got: \" + t);\n}\nclientConfig.setKeepAliveTimeout(t);","typeGuard":null,"tryCatchPattern":"try {\n  config.setKeepAliveTimeout(timeoutFromConfig);\n} catch (IllegalArgumentException e) {\n  logger.error(\"Invalid keepAliveTimeout: {}\", timeoutFromConfig);\n  config.setKeepAliveTimeout(Duration.ofSeconds(30)); // default\n}","preventionTips":["Clamp negative config values to a positive default before building the config","Do not use -1 sentinels from other frameworks as Durations here","Add validation at configuration-load time, before client construction"],"tags":["http","config","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}