{"record":{"id":"acc368b5e4e83765","repo":"eclipse-vertx/vert.x","slug":"ping-data-must-be-exactly-8-bytes-acc368","errorCode":null,"errorMessage":"Ping data must be exactly 8 bytes","messagePattern":"Ping data must be exactly 8 bytes","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/impl/http2/multiplex/Http2MultiplexConnection.java","lineNumber":336,"sourceCode":"    return promise.future();\n  }\n\n  @Override\n  public Http2Settings remoteSettings() {\n    io.netty.handler.codec.http2.Http2Settings remoteSettings = handler.remoteSettings();\n    return remoteSettings != null ? HttpUtils.toVertxSettings(remoteSettings) : null;\n  }\n\n  @Override\n  public HttpConnection remoteSettingsHandler(Handler<HttpSettings> handler) {\n    this.remoteSettingsHandler = handler;\n    return this;\n  }\n\n  @Override\n  public Future<Buffer> ping(Buffer data) {\n    if (data.length() != 8) {\n      throw new IllegalArgumentException(\"Ping data must be exactly 8 bytes\");\n    }\n    long content = data.getLong(0);\n    Promise<Buffer> promise = context.promise();\n    Http2PingFrame pingFrame = new DefaultHttp2PingFrame(content, false);\n    writeStreamFrame(pingFrame, future -> {\n      if (future.isSuccess()) {\n        pendingPingAcks.add(promise);\n      } else {\n        promise.fail(future.cause());\n      }\n    });\n    return promise.future();\n  }\n\n  @Override\n  public HttpConnection pingHandler(@Nullable Handler<Buffer> handler) {\n    this.pingHandler = handler;\n    return this;","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/http2/multiplex/Http2MultiplexConnection.java#L318-L354","documentation":"Protocol validation in Http2MultiplexConnection.ping: an HTTP/2 PING frame carries exactly 8 bytes of opaque payload. The supplied Buffer has a different length and is rejected before a frame is written, since the peer could not parse an illegal PING.","triggerScenarios":"Calling ping() with a Buffer of length != 8 on an Http2MultiplexConnection-based client/server.","commonSituations":"Sharing a ping helper between HTTP/1 keep-alive payloads and HTTP/2 where sizes differ; hashing functions producing non-8-byte outputs; forgetting that getLong(0) requires 8 readable bytes.","solutions":["Send a Buffer of exactly 8 bytes (pad or slice your data accordingly)","Use Buffer.buffer(new byte[8]) for a don't-care payload"],"exampleFix":"// before\nconn.ping(nonceBuffer); // arbitrary length\n// after\nlong token = ThreadLocalRandom.current().nextLong();\nconn.ping(Buffer.buffer(8).setLong(0, token));","handlingStrategy":"validation","validationCode":"if (data == null || data.length() != 8) throw new IllegalArgumentException(\"PING payload must be 8 bytes\");","typeGuard":"boolean isValidPingPayload(Buffer b) { return b != null && b.length() == 8; }","tryCatchPattern":"try { conn.ping(data); } catch (IllegalArgumentException e) { conn.ping(Buffer.buffer(8).setLong(0, System.nanoTime())); }","preventionTips":["Use a single helper to build 8-byte ping payloads","Don't reuse HTTP/1 keep-alive buffers for HTTP/2 PING","Assert buffer length before network calls","Encode timestamps/nonces as longs"],"tags":["http2","ping","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}