Skip to content

[Data] Fix silent data loss when a file read retries mid-file - #66011

Merged
sampan-s-nayak merged 1 commit into
masterfrom
marwan/fbds-retry-rewind
Sep 9, 2026
Merged

sampan-s-nayak merged 1 commit into
masterfrom
marwan/fbds-retry-rewind

Conversation

@marwan116

Copy link
Copy Markdown
Contributor

Description

A retryable read error partway through a file silently drops data. No exception, exit code 0.

Repro

A datasource that yields one block per 1 KiB of an 8 KiB file, with one transient error injected after the third read:

class FlakyStream:
    fired = False

    def __init__(self, f):
        self._f, self._reads = f, 0

    def read(self, n=-1):
        self._reads += 1
        if not FlakyStream.fired and self._reads > 3:
            FlakyStream.fired = True
            raise OSError(DEFAULT_RETRIED_IO_ERRORS[0])   # transient network error
        return self._f.read(n)


class ChunkedDatasource(FileBasedDatasource):
    def _open_input_source(self, filesystem, path, **kw):
        return FlakyStream(super()._open_input_source(filesystem, path, **kw))

    def _read_stream(self, f, path):
        while (data := f.read(1024)):
            builder = DelegatingBlockBuilder()
            builder.add({"data": data})
            yield builder.build()

Expected vs current

expected current this PR
blocks delivered 8 5 8
bytes delivered 8192 5120 8192
data correct yes no yes
error raised no no no

Current behavior loses 3072 bytes, 37.5% of the file, and the read reports success.

Cause

read_files opens the file once, then passes a closure over that handle to iterate_with_retry:

with RetryingContextManager(self._open_input_source(fs, read_path, ...)) as f:
    for block in iterate_with_retry(lambda: self._read_stream(f, read_path), ...):

iterate_with_retry recreates the iterable on a retryable error and skips the items the failed attempt already yielded, so the factory must replay the same sequence from the start. This one does not: it reuses the advanced handle, so attempt 2 resumes from wherever attempt 1 stopped, and the skip then discards real data instead of duplicates.

In the repro: attempt 1 yields 3 blocks and fails, attempt 2 resumes at byte 3072 and yields the remaining 5, and the first 3 of those are dropped as "already yielded". 3 + 2 = 5.

Which formats are affected

Silent loss, cut at a record boundary with one injected error at ~50%:

API current behavior
read_text silent, 1944 / 4000 rows
read_binary_files silent, payload 32768 / 65536 bytes
read_csv with column_names silent, 1501 / 4000 rows
read_json (Arrow) silent, 1961 / 4000 rows
read_csv with inferred header raises ValueError: ...check the CSV file has correct format
read_numpy raises ValueError: contains pickled (object) data
read_json (pandas JSONL) unaffected

All are correct after the fix. Whether CSV fails loudly is luck: Arrow takes the first surviving line as a header, which usually fails to parse. Supply column_names and the loss goes quiet.

Pandas JSONL escapes because #63233 added f.seek(0) to _estimate_chunksize in May 2026, which fixed an AssertionError there and incidentally restored replay-from-start for that one path. The general problem was not addressed.

Parquet is unaffected: it is not a FileBasedDatasource, and its read factory closes over a stateless fragment.

Fix

Open the file inside the retry factory, with the with scoped inside a generator so each attempt's handle is closed as soon as that attempt ends, on both the success and the exception path:

def open_and_read_stream() -> Iterator[Block]:
    with RetryingContextManager(
        self._open_input_source(fs, read_path, **open_stream_args),
        context=self._data_context,
    ) as f:
        yield from self._read_stream(f, read_path)

for block in iterate_with_retry(open_and_read_stream, ...):

Measured max 1 handle open at a time across a retry, with all handles closed on the clean, retried, and abandoned-midway paths.

Alternatives considered:

  • Rewind when the handle is seekable. _open_input_source returns open_input_stream, whose seekable() is False even on a local filesystem. This would fix only ORC and uncompressed JSON and leave everything else failing silently.
  • ExitStack around the loop. Correct, but a failed attempt's handle stays open for the remainder of that file's read, up to 10 at once.

Also documents the replay-from-start requirement on iterate_with_retry, and corrects two comments in json_datasource.py that asserted retries reuse the same handle.

Behavior change worth noting

The open now sits inside iterate_with_retry, and the open path already retries at two levels (RetryingPyFileSystem.open_input_file and RetryingContextManager.__enter__, 10 attempts each). These multiply, so a persistently retryable open can now take roughly 10x as many attempts before giving up, with exponential backoff capped at 32s per attempt. Bounded, and only in a case that was already failing.

Retries are also more expensive by design: attempt 2 re-parses the blocks it will discard. Resuming was cheaper, and wrong.

Related issues

None open. Searched open PRs and issues for iterate_with_retry, file_based_datasource retry, _read_stream retry, and RetryingContextManager. #63233 is merged and narrower, covering only the pandas JSONL chunksize path.

Additional information

Known follow-up, deliberately not in this PR. webdataset_datasource.py:439 wraps _tar_file_iterator in its own iterate_with_retry whose factory closes over the stream it was handed. That inner retry catches the error before the outer one can reopen, so a transient error there becomes tarfile.ReadError: invalid header, identically before and after this change. No regression, but it needs a separate fix. Removing a retry layer seemed like a maintainer's call.

Tests.

pytest python/ray/data/tests/datasource/test_file_based_datasource.py
  -> 32 passed, 3 skipped

New regression test test_flaky_read_stream_retry_does_not_drop_data: delivers 5 of 8 blocks on master, 8 of 8 with this change.

Wider run across the Data file-format suites (test_text, test_csv, test_json, test_binary, test_image, test_avro, test_webdataset, test_numpy, test_parquet), per file: 226 passed, 21 skipped, 30 failed. Set-differenced against the same run with this change reverted: zero new failures, one fixed. All 30 failures are missing optional imports in this environment (tensorflow x22, torch x4, decord x4) and fail identically on master.

pre-commit run is clean on the changed files.

AI assistance was used for this change: to build the repro, implement the fix, and write the tests and this description.

`FileBasedDatasource.get_read_tasks` opened each file once, outside the retry,
and handed that one handle to `iterate_with_retry`:

    with RetryingContextManager(self._open_input_source(...)) as f:
        for block in iterate_with_retry(lambda: self._read_stream(f, path), ...):

`iterate_with_retry` recreates the iterable on a retryable error and skips the
items the failed attempt already yielded, which only works if the recreated
iterable replays the same sequence from the start. The factory closed over an
already-advanced `f`, so attempt 2 resumed from wherever attempt 1 stopped and
its first N blocks were then discarded as "already yielded". The rows in
between were dropped with no error.

Measured on a datasource that yields one block per 4 KiB of a 64 KiB file,
with one `AWS Error NETWORK_CONNECTION` injected after 3 blocks: 13 of 16
blocks delivered, 12,288 bytes (18.8%) lost, exit code 0.

Reading real formats through the same injection, cut at a record boundary:

    read_text          1,944 of 4,000 rows      silent
    read_binary_files  32,768 of 65,536 bytes   silent
    read_csv           1,501 of 4,000 rows      silent (explicit column_names)
    read_json (arrow)  1,961 of 4,000 rows      silent
    read_csv           ValueError "check the CSV file has correct format"
    read_numpy         ValueError "contains pickled (object) data"

`PandasJSONDatasource` escaped because #63233 added an `f.seek(0)` to
`_estimate_chunksize`, which happens to restore the replay-from-start
contract. That fix addressed the `AssertionError` the advanced cursor caused
there; the data loss elsewhere was not covered.

Open the file inside the retry factory instead, so every attempt gets a fresh
handle and genuinely replays from byte 0. The `with` lives inside the
generator rather than in an `ExitStack` around the loop, so a failed attempt's
handle closes the moment that attempt ends: verified at most one handle open
at a time across a retry, and all handles closed on the clean, retried, and
abandoned-midway paths. Rewinding a reused handle was the other candidate, but
`_open_input_source` returns `open_input_stream`, which is not seekable, so
rewind cannot be the general fix.

Test plan (macOS, Python 3.12, per file to avoid cross-module Ray fixture
pollution, PYTHONPATH covering `data/tests` and `data/tests/datasource`):

  python/ray/data/tests/datasource/{test_file_based_datasource,test_text,
    test_csv,test_binary,test_json,test_image,test_numpy,test_avro,test_orc,
    test_tfrecords,test_webdataset,test_audio,test_video,test_mcap,
    test_file_datasink}.py
  python/ray/data/tests/test_util.py

226 passed, 21 skipped, 30 failed. The same 30 fail on master without this
change: all are missing optional imports in this environment (tensorflow,
torch, decord). The only difference between the two runs is the new test,
which delivers 5 of 8 blocks without the change and 8 of 8 with it.

AI assistance was used to write this change.

Signed-off-by: Marwan Sarieddine <[email protected]>
@marwan116
marwan116 requested a review from a team as a code owner September 8, 2026 22:36

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a potential data loss issue in FileBasedDatasource during retries of transient read errors. Previously, iterate_with_retry reused the same file handle, which resumed reading from the advanced cursor position and caused skipped blocks to discard real data. The fix opens a fresh file handle inside the factory function on each retry attempt, ensuring the file is replayed from the start. Additionally, a unit test was added to verify this behavior, and related docstrings and comments were updated. I have no further feedback to provide.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Sep 9, 2026
@marwan116 marwan116 added the go add ONLY when ready to merge, run all tests label Sep 9, 2026

@sampan-s-nayak sampan-s-nayak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for working on this, changes LGTM

@sampan-s-nayak
sampan-s-nayak merged commit 1e2cc95 into master Sep 9, 2026
6 checks passed
@sampan-s-nayak
sampan-s-nayak deleted the marwan/fbds-retry-rewind branch September 9, 2026 06:06
NightWing1998 pushed a commit to NightWing1998/ray that referenced this pull request Sep 11, 2026
…oject#66011)

## Description

A retryable read error partway through a file silently drops data. No
exception, exit code 0.

### Repro

A datasource that yields one block per 1 KiB of an 8 KiB file, with one
transient error injected after the third read:

```python
class FlakyStream:
    fired = False

    def __init__(self, f):
        self._f, self._reads = f, 0

    def read(self, n=-1):
        self._reads += 1
        if not FlakyStream.fired and self._reads > 3:
            FlakyStream.fired = True
            raise OSError(DEFAULT_RETRIED_IO_ERRORS[0])   # transient network error
        return self._f.read(n)


class ChunkedDatasource(FileBasedDatasource):
    def _open_input_source(self, filesystem, path, **kw):
        return FlakyStream(super()._open_input_source(filesystem, path, **kw))

    def _read_stream(self, f, path):
        while (data := f.read(1024)):
            builder = DelegatingBlockBuilder()
            builder.add({"data": data})
            yield builder.build()
```

### Expected vs current

|                  | expected | current    | this PR |
| ---------------- | -------- | ---------- | ------- |
| blocks delivered | 8        | **5**      | 8       |
| bytes delivered  | 8192     | **5120**   | 8192    |
| data correct     | yes      | **no**     | yes     |
| error raised     | no       | no         | no      |

Current behavior loses 3072 bytes, 37.5% of the file, and the read
reports success.

### Cause

`read_files` opens the file once, then passes a closure over that handle
to `iterate_with_retry`:

```python
with RetryingContextManager(self._open_input_source(fs, read_path, ...)) as f:
    for block in iterate_with_retry(lambda: self._read_stream(f, read_path), ...):
```

`iterate_with_retry` recreates the iterable on a retryable error and
skips the items the failed attempt already yielded, so the factory must
replay the same sequence from the start. This one does not: it reuses
the advanced handle, so attempt 2 resumes from wherever attempt 1
stopped, and the skip then discards real data instead of duplicates.

In the repro: attempt 1 yields 3 blocks and fails, attempt 2 resumes at
byte 3072 and yields the remaining 5, and the first 3 of those are
dropped as "already yielded". 3 + 2 = 5.

### Which formats are affected

Silent loss, cut at a record boundary with one injected error at ~50%:

| API | current behavior |
| ----------------------------------- |
--------------------------------------------- |
| `read_text` | silent, 1944 / 4000 rows |
| `read_binary_files` | silent, payload 32768 / 65536 bytes |
| `read_csv` with `column_names` | silent, 1501 / 4000 rows |
| `read_json` (Arrow) | silent, 1961 / 4000 rows |
| `read_csv` with inferred header | raises `ValueError: ...check the CSV
file has correct format` |
| `read_numpy` | raises `ValueError: contains pickled (object) data` |
| `read_json` (pandas JSONL) | unaffected |

All are correct after the fix. Whether CSV fails loudly is luck: Arrow
takes the first surviving line as a header, which usually fails to
parse. Supply `column_names` and the loss goes quiet.

Pandas JSONL escapes because ray-project#63233 added `f.seek(0)` to
`_estimate_chunksize` in May 2026, which fixed an `AssertionError` there
and incidentally restored replay-from-start for that one path. The
general problem was not addressed.

Parquet is unaffected: it is not a `FileBasedDatasource`, and its read
factory closes over a stateless fragment.

### Fix

Open the file inside the retry factory, with the `with` scoped inside a
generator so each attempt's handle is closed as soon as that attempt
ends, on both the success and the exception path:

```python
def open_and_read_stream() -> Iterator[Block]:
    with RetryingContextManager(
        self._open_input_source(fs, read_path, **open_stream_args),
        context=self._data_context,
    ) as f:
        yield from self._read_stream(f, read_path)

for block in iterate_with_retry(open_and_read_stream, ...):
```

Measured max 1 handle open at a time across a retry, with all handles
closed on the clean, retried, and abandoned-midway paths.

Alternatives considered:

- **Rewind when the handle is seekable.** `_open_input_source` returns
`open_input_stream`, whose `seekable()` is `False` even on a local
filesystem. This would fix only ORC and uncompressed JSON and leave
everything else failing silently.
- **`ExitStack` around the loop.** Correct, but a failed attempt's
handle stays open for the remainder of that file's read, up to 10 at
once.

Also documents the replay-from-start requirement on
`iterate_with_retry`, and corrects two comments in `json_datasource.py`
that asserted retries reuse the same handle.

### Behavior change worth noting

The open now sits inside `iterate_with_retry`, and the open path already
retries at two levels (`RetryingPyFileSystem.open_input_file` and
`RetryingContextManager.__enter__`, 10 attempts each). These multiply,
so a persistently retryable open can now take roughly 10x as many
attempts before giving up, with exponential backoff capped at 32s per
attempt. Bounded, and only in a case that was already failing.

Retries are also more expensive by design: attempt 2 re-parses the
blocks it will discard. Resuming was cheaper, and wrong.

## Related issues

None open. Searched open PRs and issues for `iterate_with_retry`,
`file_based_datasource retry`, `_read_stream retry`, and
`RetryingContextManager`. ray-project#63233 is merged and narrower, covering only
the pandas JSONL chunksize path.

## Additional information

**Known follow-up, deliberately not in this PR.**
`webdataset_datasource.py:439` wraps `_tar_file_iterator` in its own
`iterate_with_retry` whose factory closes over the stream it was handed.
That inner retry catches the error before the outer one can reopen, so a
transient error there becomes `tarfile.ReadError: invalid header`,
identically before and after this change. No regression, but it needs a
separate fix. Removing a retry layer seemed like a maintainer's call.

**Tests.**

```
pytest python/ray/data/tests/datasource/test_file_based_datasource.py
  -> 32 passed, 3 skipped
```

New regression test `test_flaky_read_stream_retry_does_not_drop_data`:
delivers 5 of 8 blocks on master, 8 of 8 with this change.

Wider run across the Data file-format suites (`test_text`, `test_csv`,
`test_json`, `test_binary`, `test_image`, `test_avro`,
`test_webdataset`, `test_numpy`, `test_parquet`), per file: 226 passed,
21 skipped, 30 failed. Set-differenced against the same run with this
change reverted: zero new failures, one fixed. All 30 failures are
missing optional imports in this environment (tensorflow x22, torch x4,
decord x4) and fail identically on master.

`pre-commit run` is clean on the changed files.

**AI assistance was used** for this change: to build the repro,
implement the fix, and write the tests and this description.

Signed-off-by: Marwan Sarieddine <[email protected]>
marwan116 added a commit that referenced this pull request Oct 2, 2026
…e_order

`MCAPDatasource` read every file through a sequential stream, so the mcap
library always took its non-seeking path:

- The summary at the file's tail (per-chunk time bounds and byte offsets,
  per-channel message counts) was unreachable. `topics` and `time_range`
  were applied per record over a full scan rather than used to skip the
  chunks that cannot match, despite the class docstring advertising
  predicate pushdown.
- `log_time_order=True` was hard-coded. On the non-seeking reader that
  loads and sorts the entire file before the first message is returned,
  which its own docstring warns about.
- A file was one block, however large it was.

Open the file for random access (`open_input_file`), the hook
`FileBasedDatasource` documents for implementations that need it.
`make_reader` then returns a `SeekingReader`, which prunes chunks by topic
and time from the index and merges chunks by log time as it goes instead of
sorting the file in memory. Files written without a summary still read: the
seeking reader falls back to a linear scan when there is no chunk index.

Cut blocks by estimated size: yield a block as soon as the builder reaches
the context's `target_max_block_size`. Memory per read task is bounded by
the target instead of by the file, and the first block of a large file
arrives before the file has been read to the end. `target_max_block_size =
None` keeps one block per file.

Expose `log_time_order` on `read_mcap`. The default, True, keeps today's
output. False streams a file in the order it was written and skips the
merge, which is the right choice when order does not matter or when the
file's chunks do not overlap in time.

Rewinding between retry attempts is no longer this class's concern:
`FileBasedDatasource.read_files` reopens the file for every attempt (#66011).

Signed-off-by: Marwan Sarieddine <[email protected]>
marwan116 added a commit that referenced this pull request Oct 5, 2026
…e_order

`MCAPDatasource` read every file through a sequential stream, so the mcap
library always took its non-seeking path:

- The summary at the file's tail (per-chunk time bounds and byte offsets,
  per-channel message counts) was unreachable. `topics` and `time_range`
  were applied per record over a full scan rather than used to skip the
  chunks that cannot match, despite the class docstring advertising
  predicate pushdown.
- `log_time_order=True` was hard-coded. On the non-seeking reader that
  loads and sorts the entire file before the first message is returned,
  which its own docstring warns about.
- A file was one block, however large it was.

Open the file for random access (`open_input_file`), the hook
`FileBasedDatasource` documents for implementations that need it.
`make_reader` then returns a `SeekingReader`, which prunes chunks by topic
and time from the index and merges chunks by log time as it goes instead of
sorting the file in memory. Files written without a summary still read: the
seeking reader falls back to a linear scan when there is no chunk index.

Cut blocks by estimated size: yield a block as soon as the builder reaches
the context's `target_max_block_size`. Memory per read task is bounded by
the target instead of by the file, and the first block of a large file
arrives before the file has been read to the end. `target_max_block_size =
None` keeps one block per file.

Expose `log_time_order` on `read_mcap`. The default, True, keeps today's
output. False streams a file in the order it was written and skips the
merge, which is the right choice when order does not matter or when the
file's chunks do not overlap in time.

Rewinding between retry attempts is no longer this class's concern:
`FileBasedDatasource.read_files` reopens the file for every attempt (#66011).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marwan Sarieddine <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…oject#66011)

## Description

A retryable read error partway through a file silently drops data. No
exception, exit code 0.

### Repro

A datasource that yields one block per 1 KiB of an 8 KiB file, with one
transient error injected after the third read:

```python
class FlakyStream:
    fired = False

    def __init__(self, f):
        self._f, self._reads = f, 0

    def read(self, n=-1):
        self._reads += 1
        if not FlakyStream.fired and self._reads > 3:
            FlakyStream.fired = True
            raise OSError(DEFAULT_RETRIED_IO_ERRORS[0])   # transient network error
        return self._f.read(n)


class ChunkedDatasource(FileBasedDatasource):
    def _open_input_source(self, filesystem, path, **kw):
        return FlakyStream(super()._open_input_source(filesystem, path, **kw))

    def _read_stream(self, f, path):
        while (data := f.read(1024)):
            builder = DelegatingBlockBuilder()
            builder.add({"data": data})
            yield builder.build()
```

### Expected vs current

|                  | expected | current    | this PR |
| ---------------- | -------- | ---------- | ------- |
| blocks delivered | 8        | **5**      | 8       |
| bytes delivered  | 8192     | **5120**   | 8192    |
| data correct     | yes      | **no**     | yes     |
| error raised     | no       | no         | no      |

Current behavior loses 3072 bytes, 37.5% of the file, and the read
reports success.

### Cause

`read_files` opens the file once, then passes a closure over that handle
to `iterate_with_retry`:

```python
with RetryingContextManager(self._open_input_source(fs, read_path, ...)) as f:
    for block in iterate_with_retry(lambda: self._read_stream(f, read_path), ...):
```

`iterate_with_retry` recreates the iterable on a retryable error and
skips the items the failed attempt already yielded, so the factory must
replay the same sequence from the start. This one does not: it reuses
the advanced handle, so attempt 2 resumes from wherever attempt 1
stopped, and the skip then discards real data instead of duplicates.

In the repro: attempt 1 yields 3 blocks and fails, attempt 2 resumes at
byte 3072 and yields the remaining 5, and the first 3 of those are
dropped as "already yielded". 3 + 2 = 5.

### Which formats are affected

Silent loss, cut at a record boundary with one injected error at ~50%:

| API | current behavior |
| ----------------------------------- |
--------------------------------------------- |
| `read_text` | silent, 1944 / 4000 rows |
| `read_binary_files` | silent, payload 32768 / 65536 bytes |
| `read_csv` with `column_names` | silent, 1501 / 4000 rows |
| `read_json` (Arrow) | silent, 1961 / 4000 rows |
| `read_csv` with inferred header | raises `ValueError: ...check the CSV
file has correct format` |
| `read_numpy` | raises `ValueError: contains pickled (object) data` |
| `read_json` (pandas JSONL) | unaffected |

All are correct after the fix. Whether CSV fails loudly is luck: Arrow
takes the first surviving line as a header, which usually fails to
parse. Supply `column_names` and the loss goes quiet.

Pandas JSONL escapes because ray-project#63233 added `f.seek(0)` to
`_estimate_chunksize` in May 2026, which fixed an `AssertionError` there
and incidentally restored replay-from-start for that one path. The
general problem was not addressed.

Parquet is unaffected: it is not a `FileBasedDatasource`, and its read
factory closes over a stateless fragment.

### Fix

Open the file inside the retry factory, with the `with` scoped inside a
generator so each attempt's handle is closed as soon as that attempt
ends, on both the success and the exception path:

```python
def open_and_read_stream() -> Iterator[Block]:
    with RetryingContextManager(
        self._open_input_source(fs, read_path, **open_stream_args),
        context=self._data_context,
    ) as f:
        yield from self._read_stream(f, read_path)

for block in iterate_with_retry(open_and_read_stream, ...):
```

Measured max 1 handle open at a time across a retry, with all handles
closed on the clean, retried, and abandoned-midway paths.

Alternatives considered:

- **Rewind when the handle is seekable.** `_open_input_source` returns
`open_input_stream`, whose `seekable()` is `False` even on a local
filesystem. This would fix only ORC and uncompressed JSON and leave
everything else failing silently.
- **`ExitStack` around the loop.** Correct, but a failed attempt's
handle stays open for the remainder of that file's read, up to 10 at
once.

Also documents the replay-from-start requirement on
`iterate_with_retry`, and corrects two comments in `json_datasource.py`
that asserted retries reuse the same handle.

### Behavior change worth noting

The open now sits inside `iterate_with_retry`, and the open path already
retries at two levels (`RetryingPyFileSystem.open_input_file` and
`RetryingContextManager.__enter__`, 10 attempts each). These multiply,
so a persistently retryable open can now take roughly 10x as many
attempts before giving up, with exponential backoff capped at 32s per
attempt. Bounded, and only in a case that was already failing.

Retries are also more expensive by design: attempt 2 re-parses the
blocks it will discard. Resuming was cheaper, and wrong.

## Related issues

None open. Searched open PRs and issues for `iterate_with_retry`,
`file_based_datasource retry`, `_read_stream retry`, and
`RetryingContextManager`. ray-project#63233 is merged and narrower, covering only
the pandas JSONL chunksize path.

## Additional information

**Known follow-up, deliberately not in this PR.**
`webdataset_datasource.py:439` wraps `_tar_file_iterator` in its own
`iterate_with_retry` whose factory closes over the stream it was handed.
That inner retry catches the error before the outer one can reopen, so a
transient error there becomes `tarfile.ReadError: invalid header`,
identically before and after this change. No regression, but it needs a
separate fix. Removing a retry layer seemed like a maintainer's call.

**Tests.**

```
pytest python/ray/data/tests/datasource/test_file_based_datasource.py
  -> 32 passed, 3 skipped
```

New regression test `test_flaky_read_stream_retry_does_not_drop_data`:
delivers 5 of 8 blocks on master, 8 of 8 with this change.

Wider run across the Data file-format suites (`test_text`, `test_csv`,
`test_json`, `test_binary`, `test_image`, `test_avro`,
`test_webdataset`, `test_numpy`, `test_parquet`), per file: 226 passed,
21 skipped, 30 failed. Set-differenced against the same run with this
change reverted: zero new failures, one fixed. All 30 failures are
missing optional imports in this environment (tensorflow x22, torch x4,
decord x4) and fail identically on master.

`pre-commit run` is clean on the changed files.

**AI assistance was used** for this change: to build the repro,
implement the fix, and write the tests and this description.

Signed-off-by: Marwan Sarieddine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants