TruncatedReply: a compressed reply the server cut at a ".\r\n" fails in 2 s; ranges:dates samples plain
Test and deploy / test (push) Successful in 53s
Test and deploy / edge (push) Successful in 1m58s
Test and deploy / deploy (push) Successful in 1m4s

Eweka stops a compressed XOVER reply at the first ".\r\n" in its own
output (78 01 2e 0d 0a and nothing more), which some small replies begin
with; the text path waited for more until the reply timeout. ranges:dates
uses plain connections of its own instead of the pool.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Fable 5.1 committed 2026-10-25 12:49:53 +01:00
1 parent 1e01702dff
commit 3cc7d9738e
5 files changed
+188 -42

No files matched your search

+95 -15
View File
@@ -1,7 +1,7 @@
import { test } from '@japa/runner'
import net from 'node:net'
import { deflateSync } from 'node:zlib'
import { MissingArticle, XoverClient, parseOverviews } from '#lib/nntp/index'
import { MissingArticle, TruncatedReply, XoverClient, parseOverviews } from '#lib/nntp/index'
import { unzipSync } from 'node:zlib'
const LINES = [
@@ -27,10 +27,15 @@ function server(): Promise<{ port: number; close: () => void }> {
pending = pending.slice(at + 2)
if (line.startsWith('AUTHINFO USER')) sock.write('381 more\r\n')
else if (line.startsWith('AUTHINFO PASS')) sock.write('281 ok\r\n')
else if (line === 'XFEATURE COMPRESS GZIP') (gzip = true), sock.write('290 Feature Enabled\r\n')
else if (line === 'XFEATURE COMPRESS GZIP')
((gzip = true), sock.write('290 Feature Enabled\r\n'))
else if (line.startsWith('GROUP')) sock.write('211 2 101 102 a.b.test\r\n')
else if (line === 'XOVER 1-1') sock.write('420 No Articles Selected\r\n')
else if (line.startsWith('XOVER')) {
else if (line === 'XOVER 5-5' && gzip) {
// As Eweka cuts a compressed reply whose output has ".\r\n" early: the zlib header, then nothing.
sock.write('224 Overview Information Follows [COMPRESS=GZIP]\r\n')
sock.write(Buffer.from([0x78, 0x01, 0x2e, 0x0d, 0x0a]))
} else if (line.startsWith('XOVER')) {
const body = Buffer.from(LINES.join('\r\n') + '\r\n')
if (gzip) {
sock.write('224 Overview Information Follows [COMPRESS=GZIP]\r\n')
@@ -53,19 +58,32 @@ function server(): Promise<{ port: number; close: () => void }> {
else if (line.startsWith('BODY')) {
sock.write('222 0 <one@test> body\r\n')
// Raw bytes, a dot-stuffed line among them.
send(Buffer.concat([Buffer.from([0x3d, 0x79, 0xff, 0x00, 0x0d, 0x0a]), Buffer.from('..stuffed\r\nlast\r\n.\r\n')]))
send(
Buffer.concat([
Buffer.from([0x3d, 0x79, 0xff, 0x00, 0x0d, 0x0a]),
Buffer.from('..stuffed\r\nlast\r\n.\r\n'),
])
)
} else if (line === 'QUIT') sock.end('205 bye\r\n')
}
})
})
srv.listen(0, '127.0.0.1', () => resolve({ port: (srv.address() as net.AddressInfo).port, close: () => srv.close() }))
srv.listen(0, '127.0.0.1', () =>
resolve({ port: (srv.address() as net.AddressInfo).port, close: () => srv.close() })
)
})
}
test.group('nntp / XoverClient', () => {
test('reads a body by message-id as bytes, raw; 430 is MissingArticle', async ({ assert }) => {
const { port, close } = await server()
const client = await XoverClient.connect({ host: '127.0.0.1', port, user: 'u', password: 'p', compress: false })
const client = await XoverClient.connect({
host: '127.0.0.1',
port,
user: 'u',
password: 'p',
compress: false,
})
try {
const body = await client.body('one@test')
assert.deepEqual([...body.subarray(0, 6)], [0x3d, 0x79, 0xff, 0x00, 0x0d, 0x0a])
@@ -81,7 +99,13 @@ test.group('nntp / XoverClient', () => {
test('reads several bodies pipelined, in order, a missing one as null', async ({ assert }) => {
const { port, close } = await server()
const client = await XoverClient.connect({ host: '127.0.0.1', port, user: 'u', password: 'p', compress: false })
const client = await XoverClient.connect({
host: '127.0.0.1',
port,
user: 'u',
password: 'p',
compress: false,
})
try {
const bodies = await client.bodies(['one@test', '<gone@test>', '<one@test>'])
assert.equal(bodies.length, 3)
@@ -105,14 +129,25 @@ test.group('nntp / XoverClient', () => {
})
for (const compress of [false, true]) {
test(`fetches overviews ${compress ? 'gzip-compressed' : 'plain'}, and an empty range`, async ({ assert }) => {
test(`fetches overviews ${compress ? 'gzip-compressed' : 'plain'}, and an empty range`, async ({
assert,
}) => {
const { port, close } = await server()
const client = await XoverClient.connect({ host: '127.0.0.1', port, user: 'u', password: 'p', compress })
const client = await XoverClient.connect({
host: '127.0.0.1',
port,
user: 'u',
password: 'p',
compress,
})
try {
assert.equal(client.compressed, compress)
assert.deepEqual(await client.group('a.b.test'), { count: 2, low: 101, high: 102 })
const overviews = await client.xover(101, 102)
assert.deepEqual(overviews.map(([n]) => n), [101, 102])
assert.deepEqual(
overviews.map(([n]) => n),
[101, 102]
)
assert.equal(overviews[1][1].subject, 'Show.S01E01 - "a.mkv" yEnc (2/2)')
assert.deepEqual(await client.xover(1, 1), [])
assert.lengthOf(await client.xover(101, 102), 2)
@@ -127,9 +162,43 @@ test.group('nntp / XoverClient', () => {
})
}
test('idle time between commands does not count against the reply timeout', async ({ assert }) => {
test('a compressed reply cut short at a ".\\r\\n" in its output fails as TruncatedReply, well before the reply timeout', async ({
assert,
}) => {
const { port, close } = await server()
const client = await XoverClient.connect({ host: '127.0.0.1', port, user: 'u', password: 'p', compress: true, timeoutMs: 200 })
const client = await XoverClient.connect({
host: '127.0.0.1',
port,
user: 'u',
password: 'p',
compress: true,
timeoutMs: 60_000,
})
try {
await client.group('a.b.test')
const startedAt = Date.now()
await assert.rejects(() => client.xover(5, 5), TruncatedReply)
assert.isBelow(Date.now() - startedAt, 10_000)
// The connection is still usable: the server thinks it answered.
assert.lengthOf(await client.xover(101, 102), 2)
} finally {
client.close()
close()
}
}).timeout(10_000)
test('idle time between commands does not count against the reply timeout', async ({
assert,
}) => {
const { port, close } = await server()
const client = await XoverClient.connect({
host: '127.0.0.1',
port,
user: 'u',
password: 'p',
compress: true,
timeoutMs: 200,
})
try {
await client.group('a.b.test')
await new Promise((resolve) => setTimeout(resolve, 500))
@@ -141,13 +210,24 @@ test.group('nntp / XoverClient', () => {
})
for (const compress of [false, true]) {
test(`hands out overviews as one zlib stream (${compress ? 'as the server sent it' : 'deflated here'})`, async ({ assert }) => {
test(`hands out overviews as one zlib stream (${compress ? 'as the server sent it' : 'deflated here'})`, async ({
assert,
}) => {
const { port, close } = await server()
const client = await XoverClient.connect({ host: '127.0.0.1', port, user: 'u', password: 'p', compress })
const client = await XoverClient.connect({
host: '127.0.0.1',
port,
user: 'u',
password: 'p',
compress,
})
try {
await client.group('a.b.test')
const raw = await client.xoverRaw(101, 102)
assert.deepEqual(parseOverviews(unzipSync(raw).toString('utf8')).map(([n]) => n), [101, 102])
assert.deepEqual(
parseOverviews(unzipSync(raw).toString('utf8')).map(([n]) => n),
[101, 102]
)
assert.lengthOf(parseOverviews(unzipSync(await client.xoverRaw(1, 1)).toString('utf8')), 0)
} finally {
client.close()