Repository navigation
RServer: close the connection on a positive reply the command didn't expect - #388
Merged
Merged
Conversation
…expect #381 closes a connection that still holds buffered bytes before the next command. A block that a broken or hostile news server sends after an unexpected positive status line, but only once NewsCache has sent its next command (a separate TCP segment, a pause), isn't in the buffer then, and its first line was read as the next command's reply. Only the replies a command expects tell where their block ends (RFC 3977 3.1). reply_unexpected() closes the connection when a command rejects a positive reply (1xx, 2xx, 3xx); a 4xx or 5xx is one line and keeps it, so a 411 or 430 costs no reconnect. Called where issue()'s expected code doesn't match, in selectgroup, listgroup, liststep, article by number, the ARTICLE <id> paths of RServer and CServer, the OVER/XOVER fallback (a positive reply other than 224 now fails the range instead of switching OVER off) and the three POST/STAT checks. The set-up replies in connect() (MODE READER, COMPRESS, LIST OVERVIEW.FMT) are left as they are: a wrong positive reply there is ignored and the command switched off for later connections; failing the connection instead made such a server unusable (it answers each new connection the same way), and a late block there reaches only the next set-up command, after which #381's check closes the connection. TestUpstreamUnexpectedBlockLater: the status line at once, the block two seconds later (Faults.Split), for GROUP, ARTICLE n, OVER, LISTGROUP and ARTICLE <id>. The next line the server gets must open a new connection (MODE READER), and the follow-up command must get its own reply. All five fail on main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sitive reply The first version failed the range on a positive reply other than 224: a server that always answers OVER that way would fail every overview request, with a reconnect each time. Now the connection is closed (the reply may come with a block) and XOVER is tried on a new one, as for any other reply before. (Round 0 review.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
liststep and probelisted kept F_LISTGROUP after a positive reply other than 211, so a server that always answers LISTGROUP that way cost a new connection at every step (reply_unexpected closes it). Such a reply counts as unsupported now (listgroup_unsupported), as listgroup() already treats any non-211 reply: the overview records are used. (Round 1 review note.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
listgroup_unsupported() looked only at the reply, and CNewsgroup's and RNewsgroup's LISTGROUP catches don't check the command: a refused GROUP (now also an unexpected positive reply to it) on the way counted as an unsupported LISTGROUP and fell back to the overview. It checks that the failed command is LISTGROUP now. liststep also switches LISTGROUP off after an unexpected positive reply, as listgroup() does, so the client LISTGROUP path doesn't make a new connection per request either. (Review council round 2, Terra.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
go-while
added a commit
that referenced
this pull request
Nov 17, 2026
…1.3.23 Folds the changes/ entries merged into main since the last sync and removes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follow-up to #381. #381 closes an upstream connection that still holds buffered bytes before the next command. A broken or hostile news server can answer a command with a positive reply the command doesn't expect (215 and a list in reply to GROUP, 222 and a body in reply to ARTICLE) and send the block's lines only after NewsCache has sent its next command (a separate TCP segment, a pause). Those lines aren't in the buffer then, and the first one was read as the next command's reply: an article the server has came back as 430, or an internal command (LISTGROUP after ARTICLE, XOVER after OVER) got the stray line.
Only the replies a command expects tell where their block ends (RFC 3977 3.1).
Change (NServer-0.9.1/NServer.cc):
RServer::reply_unexpected(): when a command rejects a positive reply (1xx, 2xx, 3xx), close the connection; the next command makes a new one. A 4xx or 5xx reply is one line and keeps the connection, so a 411 or 430 costs no reconnect.issue()'s expected code doesn't match, inselectgroup,listgroup,liststep,articleby number, the ARTICLE<id>paths of RServer and CServer, the OVER/XOVER fallback (the connection is closed, then XOVER is tried on a new one as before), and the three POST/STAT checks.listgroup_unsupported()(NSError.h): only LISTGROUP's own reply counts; a positive reply other than 211 to it counts as unsupported, so LISTGROUP is switched off for that server and the overview records are used, instead of a new connection at every step (liststepswitches it off too). A refused GROUP on the way stays an upstream error.listgroup(), which switches it off on any reply other than 211.connect()(MODE READER, COMPRESS, LIST OVERVIEW.FMT). A wrong positive reply there is ignored and the command switched off for later connections, as before; failing the connection made such a server unusable (it answers each new connection the same way; three corpus cases showed it), and a late block there reaches only the next set-up command, after which RServer: close a connection that has more than the reply buffered #381's check closes the connection.Test:
TestUpstreamUnexpectedBlockLater(tests/e2e/replycorpus_test.go): the status line at once, the block two seconds later (Faults.Split), for GROUP, ARTICLE n, OVER, LISTGROUP and ARTICLE<id>. The next line the server gets must open a new connection (MODE READER), the follow-up command must get its own reply, DATE and QUIT must stay in sync.Test-host runs (jobq, any free container):
make checkpasses (C++ checks, full e2e), TestUpstreamReplyCorpus and TestUpstreamUnexpectedBlockLater pass;make check, the corpus, the new test and the LISTGROUP tests pass;Review: round 0 haiku 9, sonnet 9, luna 9 (after cross-check; OVER fallback restored in 48f2cae); council r1: terra 10, sonnet 9; r2: sonnet 9, terra 7 (fixed in 40c93e4); r3: sonnet 9, terra 8 (the LISTGROUP-off-per-session point, accepted as a design choice after review).
🤖 Generated with Claude Code