Skip to content

ByteFlow.runToInputStream bulk reads wait until the requested length or EOF #354

Description

@Mendrejk

Problem

InputStream.read(byte[], off, len) from ByteFlow.runToInputStream continues reading until len bytes are filled or the stream ends. Short reads are not returned once some data is available.

Impact

Consumers that request large buffers, including Jackson’s array parser (~8 KiB), can stall or deadlock with incremental/demand-driven sources even when enough bytes are already available to decode the next value.

Related consequences of the current bridge:

  • Concurrent read-ahead through the channel buffer.
  • Early cancellation may hang if upstream is blocked in a non-interruptible InputStream.read.

Expected

Bulk reads should return after copying currently available bytes (legal short reads), matching normal InputStream behavior.

Suggested tests

  • Source emits a small chunk and then waits; a bulk read returns the available bytes without waiting for more.
  • Offset/length and empty-chunk cases still behave correctly.

Follow-up after fix

In the JSON module, strengthen parseArray latency/cancellation regressions to assert prompt element emission.

Notes

Discovered while adding the JSON module. Array parsing currently uses this API and inherits the limitation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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