Commit 0e758b4
committed
Bugfix: range_read cancellation lands within ~64 KB, not 16 MB
- The cancel flag was checked only between `get_lines` chunks (one per 4096 lines). For 4 KB/line files that meant 16 MB of uninterruptible read between checks, violating design-principles §3 "long operations are always cancelable." Added an inner-loop check that fires every 256 lines or every 64 KB of emitted output, whichever lands first. At typical 80-byte lines that's a check every ~20 KB; at pathological 4 KB lines it's every 16 lines.
- Rewrote the cancellation test to be deterministic: the previous version raced `thread::sleep(5ms)` against the read on a ~1 MB file and accepted `Ok | Cancelled` as a pass, which made the assertion meaningless. New shape:
- `read_range_cancellation_returns_cancelled`: pre-flips the cancel flag, invokes `range_read::read_range` directly on a `FullLoadBackend`, asserts `matches!(result, Err(ViewerError::Cancelled))` strictly.
- `read_range_session_cancellation_returns_cancelled_and_cleans_up`: end-to-end through the session on a 16 MB file (4096 lines × 4 KB). The read can't complete in the canceller's 2 ms sleep, so the in-loop check is exercised every iteration and the cancel lands. Also re-asserts `active_read_count == 0` post-cancel.
- While there: documented the CRLF assumption in `range_read.rs`. All three backends (`byte_seek.rs:118`, `full_load.rs:43`, `line_index.rs:172`) keep `\r` AS PART of the returned line string — they only split on `\n` and slice up to (but excluding) the `\n` byte. So `line.len()` already includes the `\r` for CRLF files; the `+ 1` in `chunk_end_offset` accounts only for the single `\n` delimiter. No drift on either LF or CRLF files. Added `read_range_full_load_crlf_preserves_carriage_returns` to pin this so a future "auto-strip \r" change doesn't silently drift `byte_offset`.1 parent e29312b commit 0e758b4
2 files changed
Lines changed: 114 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
150 | 158 | | |
151 | 159 | | |
152 | 160 | | |
| 161 | + | |
| 162 | + | |
153 | 163 | | |
154 | 164 | | |
155 | 165 | | |
| |||
161 | 171 | | |
162 | 172 | | |
163 | 173 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
167 | 183 | | |
168 | 184 | | |
169 | 185 | | |
| |||
172 | 188 | | |
173 | 189 | | |
174 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
175 | 202 | | |
176 | 203 | | |
177 | 204 | | |
| |||
180 | 207 | | |
181 | 208 | | |
182 | 209 | | |
| 210 | + | |
183 | 211 | | |
184 | 212 | | |
185 | 213 | | |
| |||
196 | 224 | | |
197 | 225 | | |
198 | 226 | | |
| 227 | + | |
| 228 | + | |
199 | 229 | | |
200 | 230 | | |
201 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
547 | 576 | | |
548 | | - | |
549 | | - | |
| 577 | + | |
550 | 578 | | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
556 | 586 | | |
557 | 587 | | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
571 | 601 | | |
572 | | - | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
573 | 628 | | |
574 | 629 | | |
575 | 630 | | |
| |||
0 commit comments