Repository navigation
fix: surface PGN read errors instead of looping forever - #132
Merged
Merged
Conversation
The PGN framer called readMore again after a read failure whenever the buffer still held bytes, so a reader that kept failing (a dropped connection, for instance) made the decoder spin instead of reporting the error. The buffered bytes of a failed read are an incomplete record, so the read error is now returned to the caller, and any complete record already buffered is returned first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3 #132 +/- ##
==========================================
+ Coverage 85.38% 85.53% +0.14%
==========================================
Files 46 46
Lines 6399 6395 -4
==========================================
+ Hits 5464 5470 +6
+ Misses 686 680 -6
+ Partials 249 245 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pgnFramer.next()calledreadMore()again after a read failure whenever the buffer still held bytes. A reader that keeps failing — a dropped connection, for instance — therefore made the decoder spin forever instead of reporting the error:Reproduced against
v3with a reader that returns one game and then a persistent error; the call never returned (killed after 300s).Fix
The bytes left in the buffer after a failed read are an incomplete record, so the read error is now returned to the caller instead of reading again. A record that was fully read before the failure is still returned first.
readMoreno longer writesf.readErritself; the framer owns that state.Tests
pgn_read_error_test.go(new):TestPGNDecoderReportsReadError— the decoder returns the reader's error. Fails onv3(times out), passes here.TestPGNGamesReportsReadError— the iterator surfaces the error too.TestPGNDecoderReturnsCompleteRecordBeforeReadError— a record fully read before the failure is still returned; the error surfaces on the next call.TestPGNDecoderCleanEndStillReturnsEOF— a clean end still reportsio.EOF.go test ./...passes.golangci-lint run --new-from-rev=origin/v3reports 0 issues.Note
This is the v3 counterpart of #129, not a cherry-pick of it: v3 has no
Scanner(it was replaced byPGNDecoder/PGNGames/PGNRecords), so #129'sScanner.LastError()has no target here. The underlying need — a read error reaching the user — is already served in v3 by returning errors in-band, except for the hang fixed here.Related: #129 is what surfaced the v2 half of this problem —
bufio.Scanner's default 64 KiB token limit rejects the longest possible chess game outright (bufio.Scanner: token too long), soScanner.LastError()reports a failure the caller can do nothing about. On v2 that needs a token-limit fix, not just visibility.