Skip to content

Test a stream read that fails on the first attempt - #1490

Open
subtilitas wants to merge 1 commit into
jbeder:masterfrom
subtilitas:test-first-read-failure
Open

Test a stream read that fails on the first attempt#1490
subtilitas wants to merge 1 commit into
jbeder:masterfrom
subtilitas:test-first-read-failure

Conversation

@subtilitas

Copy link
Copy Markdown

FailingStreamBuf serves 32 bytes before it throws, so Stream's constructor completes and the failure is raised later, while scanning. Stream's constructor ends in ReadAheadTo(0), so a buffer that throws immediately raises it from inside the constructor instead - a path nothing covered.

It is also the path that leaked before m_pPrefetched became a unique_ptr: a destructor does not run for an object whose constructor threw. Restoring the raw pointer keeps every existing test passing and green, while this one reports 2048 bytes leaked under AddressSanitizer.

FailingStreamBuf serves 32 bytes before it throws, so Stream's constructor
completes and the failure is raised later, while scanning.  Stream's constructor
ends in ReadAheadTo(0), so a buffer that throws immediately raises it from
inside the constructor instead - a path nothing covered.

It is also the path that leaked before m_pPrefetched became a unique_ptr: a
destructor does not run for an object whose constructor threw.  Restoring the
raw pointer keeps every existing test passing and green, while this one reports
2048 bytes leaked under AddressSanitizer.
Copilot AI lite review requested due to automatic review settings September 3, 2026 20:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is a focused, correct test addition that increases coverage for an important constructor-failure path without altering production behavior.

Pull request overview

Adds an integration test to cover the YAML::Stream constructor failure path when the underlying std::streambuf throws on the first prefetch read, ensuring Load(std::istream&) consistently translates that failure into BadStream (and guarding against regressions in constructor-exception/leak scenarios).

Changes:

  • Introduce ImmediatelyFailingStreamBuf, a std::stringbuf that throws on its first xsgetn call.
  • Add RejectsInputStreamFailureOnFirstRead to verify Load(stream) throws BadStream when the first prefetch read fails.
File summaries
File Description
test/integration/load_node_test.cpp Adds a new failing streambuf and a new test to exercise the “failure during Stream construction / first prefetch” path.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@SGSSGene

SGSSGene commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

I am sorry, I have trouble understanding what this PR is for. To me it sounds you are raising an issue and this PR demonstrates it?

@subtilitas

Copy link
Copy Markdown
Author

I am sorry, I have trouble understanding what this PR is for. To me it sounds you are raising an issue and this PR demonstrates it?

Yes, the issue itself has been fixed on master, but your test is incomplete so that's my suggestion.
I ran into the leak with 0.8 while testing my library and found it closed but still untested.
That's what I propose here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants