Skip to content

RServer: close the connection on a positive reply the command didn't expect - #388

Merged
go-while merged 4 commits into
mainfrom
fix/unexpected-positive-reply
Nov 16, 2026
Merged

go-while merged 4 commits into
mainfrom
fix/unexpected-positive-reply

Conversation

@go-while

@go-while go-while commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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.
  • 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 (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 (liststep switches it off too). A refused GROUP on the way stays an upstream error.
  • Decided design choice: after one such odd reply, LISTGROUP stays off for that server for the rest of the client's session (one process per client); later LISTGROUP requests use the overview path, slower but never wrong data. Stricter than listgroup(), which switches it off on any reply other than 211.
  • Not changed: the set-up replies in 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):

  • branch 95d130f on Ubuntu 26.04 and 48f2cae on Fedora 44: make check passes (C++ checks, full e2e), TestUpstreamReplyCorpus and TestUpstreamUnexpectedBlockLater pass;
  • fa6c141 on AlmaLinux 10 and 40c93e4 on Alpine 3.22: make check, the corpus, the new test and the LISTGROUP tests pass;
  • main 315d0dd + the new test only, on Fedora 46: all five cases fail.

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

go-while and others added 4 commits November 16, 2026 21:28
…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
go-while merged commit ea6bfb3 into main Nov 16, 2026
31 checks passed
@go-while
go-while deleted the fix/unexpected-positive-reply branch November 16, 2026 23:51
go-while added a commit that referenced this pull request Nov 17, 2026
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>
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.

1 participant