Skip to content

fix(stream): avoid EOF when decoding ext into pointer/interface destinations - #148

Merged
shamaton merged 3 commits into
mainfrom
fix/stream-ext-eof
Oct 25, 2026
Merged

shamaton merged 3 commits into
mainfrom
fix/stream-ext-eof

Conversation

@shamaton

Copy link
Copy Markdown
Owner

Summary

  • Fix EOF errors in UnmarshalRead when a custom stream ext decoder is registered
  • Decoded ext values are now set directly into pointer and interface destinations
  • Consumed ext frames that no decoder claims now return a type-mismatch error

Background

#117 (v3.2.2) added tryExtDecode before the kind switch. Once a custom stream ext coder is registered alongside the built-in time decoder, the ext frame is consumed before the destination type is checked. On a mismatch the decoder fell back to kind-based decoding, which read the frame again and hit EOF. Affected destinations include interface{}, *T, map[string]interface{}, []interface{}, pointer struct fields, and complex types. This applies to both custom ext and time values. The buffer decoder (Unmarshal) and v2 are not affected.

Changes

  • Store ext-decoded values into pointer and interface destinations, matching Unmarshal
  • Return a type-mismatch error instead of falling through once a frame has been consumed
  • Skip ext dispatch for complex destinations, which decode their own ext frame
  • Regression tests comparing UnmarshalRead with Unmarshal across custom ext, time, and complex destinations
  • Remove the EOF special-case from TestDecodeUnhashableExtMapKey

Test Plan

  • go vet ./... and go test -race ./...
  • The new tests fail on main (17 cases) and pass with this change
  • Interleaved benchmarks against main show no significant change in time or allocations

Notes

  • Ext frames that no decoder claims now return a type-mismatch error instead of EOF. Is that the right behavior?

…ations

When a custom stream ext decoder was registered, tryExtDecode consumed the
ext frame and then fell back to kind-based decoding for pointer and
interface destinations, which read the frame again and failed with EOF.
Fill pointer/interface destinations directly from the decoded value and
report an error when a consumed frame is not claimed by any decoder.
Complex destinations are left to the kind switch, which decodes their
dedicated ext frame itself.
@github-actions github-actions Bot added the type: bug Confirmed or likely defect label Oct 25, 2026
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.78%. Comparing base (7baccf3) to head (f6cd129).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
+ Coverage   92.56%   92.78%   +0.21%     
==========================================
  Files          75       75              
  Lines        7157     7189      +32     
==========================================
+ Hits         6625     6670      +45     
+ Misses        330      319      -11     
+ Partials      202      200       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shamaton
shamaton merged commit efa1941 into main Oct 25, 2026
27 checks passed
@shamaton
shamaton deleted the fix/stream-ext-eof branch October 25, 2026 12:29
@github-actions github-actions Bot mentioned this pull request Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Confirmed or likely defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant