{"record":{"id":"52e10aa622f8a939","repo":"eclipse-vertx/vert.x","slug":"ping-data-must-be-exactly-8-bytes","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/codec/Http2ConnectionImpl.java","lineNumber":436,"sourceCode":"      }\n      promise.complete();\n    };\n    updateSettingsHandlers.add(pending);\n    handler.writeSettings(settingsUpdate).addListener(fut -> {\n      if (!fut.isSuccess()) {\n        synchronized (Http2ConnectionImpl.this) {\n          updateSettingsHandlers.remove(pending);\n        }\n        promise.fail(fut.cause());\n      }\n    });\n    return promise.future();\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    Promise<Buffer> promise = context.promise();\n    handler.writePing(data.getLong(0)).addListener(fut -> {\n      if (fut.isSuccess()) {\n        synchronized (Http2ConnectionImpl.this) {\n          pongHandlers.add(promise);\n        }\n      } else {\n        promise.fail(fut.cause());\n      }\n    });\n    return promise.future();\n  }\n\n  @Override\n  public synchronized HttpConnection pingHandler(Handler<Buffer> handler) {\n    pingHandler = handler;\n    return this;","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/http2/codec/Http2ConnectionImpl.java#L418-L454","documentation":"HTTP/2 PING frames carry exactly 8 bytes of opaque payload per RFC 7540. Http2ConnectionImpl.ping(Buffer) validates the buffer length and throws IllegalArgumentException otherwise, before writing the ping to the connection.","triggerScenarios":"Calling connection.ping(buffer) with a buffer whose length() is not 8 (e.g. 0-byte, 4-byte timestamp, 16-byte token).","commonSituations":"Measuring latency with a System.nanoTime() encoded in 8 bytes but accidentally wrapping the wrong byte count; padding or prefixing the payload with extra bytes; reusing a generic nonce generator producing different sizes.","solutions":["Build exactly an 8-byte Buffer, e.g. Buffer.buffer(8).setLong(0, System.nanoTime()).","Check data.length() == 8 before calling ping().","If you need larger payloads, send them over a data stream instead of PING."],"exampleFix":"// before\nconn.ping(Buffer.buffer(\"ping-me\"));\n// after\nBuffer payload = Buffer.buffer(8).setLong(0, System.nanoTime());\nconn.ping(payload);","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, 0L)); }","preventionTips":["Always construct ping payloads with Buffer.buffer(8).setLong(0, value)","Wrap ping in a helper that encodes longs","Add a length assertion in latency-probe utilities","Remember RFC 7540 fixes PING payload at 8 bytes"],"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-14T00:17:10.932Z"}