Skip to content

Producer: Split produce function into fetch/process & Proper Handling for Incomplete Error - #2636

Merged
AmmarAbouZor merged 4 commits into
esrlabs:masterfrom
AmmarAbouZor:split-producer-and-fix
Sep 1, 2026
Merged

AmmarAbouZor merged 4 commits into
esrlabs:masterfrom
AmmarAbouZor:split-producer-and-fix

Conversation

@AmmarAbouZor

Copy link
Copy Markdown
Contributor

This PR closes #2413
This PR closes #2635

It splits Producer::produce_next() into a cancel-safe fetch() and a process() step, keeping the original method for
existing call sites.
And also it fixes silent data loss when a source (process/serial) receives a line longer than the internal buffer, which led to corruption of pending items and incorrect line splitting when a source stalls mid-read.

  • Process and serial sources reported the requested line length instead of the actually buffered bytes, so the
    producer believed more data had arrived than write_from()'s silent truncation allowed.
  • Parsers now hand back their held bytes via parse_remaining(), so a stalled source no longer erodes a pending
    item byte by byte and text lines no longer split at reader buffer boundaries.
  • can_buffer_more() now distinguishes a full buffer from a paused source, resolving remainders only when
    actually needed.

It also includes additional fixes for multiple issues found in the refactoring:

  • Fixes the CLI socket session sending duplicate, ever-growing message batches each round.
  • Fixes the export command producing incomplete or miscounted output.
  • Includes clippy fixes unrelated to the above, triggered by a newer Rust toolchain.

Change Producer API to split the existing method produce_next() into two
methods:
* Fetch to read data from data source which mush be cancel safe
* Process to parse the data which doesn't require cancel safety

The changes still preserve the existing method as it's used in multiple
other places.
`write_from()` truncates silently when the buffer is full, but the
process and serial sources reported the length of the received line
instead. On a line longer than the 8192-byte buffer that makes the
producer believe bytes arrived which never did.
* Parsers hand back the bytes they still hold through
  `parse_remaining()`, so a stalled source no longer erodes a pending
  item one byte per parse call, and text lines stop splitting at reader
  buffer boundaries.
* `can_buffer_more()` tells a full buffer from a merely paused source,
  which is the only case where a remainder must be resolved right away.

Fixes for additionally discovered bugs:
* The CLI socket session rewrote every message it had ever collected on
  each round.
* The export read-to-end loop never drained its records and counted
  rounds instead of messages.
Fixes came from new rust version and not from the changes in this branch
@AmmarAbouZor
AmmarAbouZor force-pushed the split-producer-and-fix branch from 0256289 to 8be26af Compare September 1, 2026 07:49
@AmmarAbouZor
AmmarAbouZor merged commit 28c266b into esrlabs:master Sep 1, 2026
1 check passed
@AmmarAbouZor
AmmarAbouZor deleted the split-producer-and-fix branch September 1, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Producer: Proper Handling for Incomplete Parser Error Split Producer main function into two functions for cancel safety.

1 participant