AsyncIterator icon indicating copy to clipboard operation
AsyncIterator copied to clipboard

Cloning a ClonedIterator doesn't preserve HistoryReader from original source

Open constraintAutomaton opened this issue 2 months ago • 0 comments

Cloning a ClonedIterator doesn't preserve HistoryReader from original source

Description

When cloning an AsyncIterator that is itself already a clone, the new clone doesn't share the same HistoryReader as the original source. This causes the newly cloned stream to:

  • Not start at the expected position
  • Not end at the expected position

The issue appears to stem from this code in the clone implementation:

const history = (source && (source as any)[DESTINATION]) ||
      (source[DESTINATION] = new HistoryReader<T>(source) as any);

The problem seem to be that when source is itself a ClonedIterator, the code doesn't attempt to retrieve the HistoryReader from the original source iterator. Instead, it creates or uses a HistoryReader directly on the ClonedIterator, or create a new HistoryReader which can cause lost of results .

constraintAutomaton avatar Oct 21 '25 11:10 constraintAutomaton