Skip to content

NonBlockingBufferReader enters an infinite loop #714

@lucarosellini

Description

@lucarosellini

Describe the bug
We hit an edge case in our production environment where NonBlockingBufferReader#readLines enters an infinite loop when the input file has lines with different lengths.

To Reproduce
Steps to reproduce the behaviour:

  1. Generate an input file with two lines:
    • First line's length shorter than the NonBlockingBufferReader's buffer initialCapacity.
    • Second line's length >= initialCapacity.
  2. parameter minRecords passed to NonBlockingBufferReader#readLines should be > 1.

Expected behavior
NonBlockingBufferReader should read all lines of the input file.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
In master...lucarosellini:kafka-connect-file-pulse:different-lengths-issue I've added a new test case to reproduce the issue.
To do this, I had to perform some minor refactoring of the test code. These changes are not intended to be merged into master; they are solely for reproducing the issue.

The problem lies in the while loop in readLines(). If the first line is shorter than the buffer capacity, it is read and added to the records collection.

The while loop continues reading input bytes until bufferOffset equals buffer.length. At that point, nread is always 0 because the len parameter passed to reader.read() is 0.

Since records is not empty (we’ve already read one full line), the if condition is never true due to the records.isEmpty() check and the buffer is never expanded.
As a result, the loop becomes infinite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions