Skip to content

fix(nntp): materialize ARTICLE/HEAD/BODY multiline data to prevent em…#23

Open
ros32 wants to merge 1 commit intokeimpema:masterfrom
ros32:fix-enumerate-body
Open

fix(nntp): materialize ARTICLE/HEAD/BODY multiline data to prevent em…#23
ros32 wants to merge 1 commit intokeimpema:masterfrom
ros32:fix-enumerate-body

Conversation

@ros32
Copy link
Copy Markdown

@ros32 ros32 commented Oct 17, 2025

…pty bodies

The NNTP parser returned deferred IEnumerable<string> body lines backed by an enumerator created inside a using block. In some usage patterns (e.g., deferred enumeration, interleaved NNTP commands, keepalive/parallel workers) the enumerator would be disposed before consumers enumerated it, yielding empty bodies.

Change:

  • In lib/Usenet/Usenet/Nntp/Parsers/ArticleResponseParser.cs (Parse):
    • Copy dataBlock to a list (var lines = dataBlock?.ToList();)
    • Enumerate headers from this list
    • Materialize body with EnumerateBodyLines(enumerator).ToList()
    • Return NntpArticle with fully materialized Body

Why now:

  • Recent calling patterns defer enumeration and/or issue additional NNTP commands between parse and consumption, exposing the latent bug.

Notes:

  • RFC 3977 compliance preserved; dot-stuffing and terminator remain handled by NntpStreamReader.
  • No public API changes; minor memory overhead per article body in exchange for correctness.

…pty bodies

The NNTP parser returned deferred `IEnumerable<string>` body lines backed by an enumerator created inside a `using` block. In some usage patterns (e.g., deferred enumeration, interleaved NNTP commands, keepalive/parallel workers) the enumerator would be disposed before consumers enumerated it, yielding empty bodies.

Change:
- In `lib/Usenet/Usenet/Nntp/Parsers/ArticleResponseParser.cs` (Parse):
  - Copy `dataBlock` to a list (`var lines = dataBlock?.ToList();`)
  - Enumerate headers from this list
  - Materialize body with `EnumerateBodyLines(enumerator).ToList()`
  - Return `NntpArticle` with fully materialized `Body`

Why now:
- Recent calling patterns defer enumeration and/or issue additional NNTP commands between parse and consumption, exposing the latent bug.

Notes:
- RFC 3977 compliance preserved; dot-stuffing and terminator remain handled by `NntpStreamReader`.
- No public API changes; minor memory overhead per article body in exchange for correctness.
@JohnTasler
Copy link
Copy Markdown
Contributor

@ros32, I recommend moving this PR into the fork at https://github.com/Spottarr/Usenet. It is being maintained more actively, and the PR will probably be merged much more quickly than if you leave it on this original fork.

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.

2 participants