Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-16393

SslTransportLayer doesn't implement write(ByteBuffer[], int, int) correctly

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.8.0
    • None
    • None

    Description

      As of Kafka 3.7.0, SslTransportLayer.write(ByteBuffer[], int, int) is implemented like below:

      public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
          ...
          int i = offset;
          while (i < length) {
              if (srcs[i].hasRemaining() || hasPendingWrites()) {
          ....
      

      The loop index starts at `offset` and ends with `length`.
      However this isn't correct because end-index should be `offset + length`.

      Let's say we have the array of ByteBuffer with length = 5 and try calling this method with offset = 3, length = 1.

      In current code, `write(srcs, 3, 1)` doesn't attempt any write because the loop condition is immediately false.

      For now, seems this method is only called with args offset = 0, length = srcs.length in Kafka code base so not causing any problem though, we should fix this because this could introduce subtle bug if use this method with different args in the future.

      Attachments

        Issue Links

          Activity

            People

              ocadaruma Haruki Okada
              ocadaruma Haruki Okada
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: