Skip to content

Raise the response read buffer to 128KiB - #150

Merged
MDA2AV merged 1 commit into
mainfrom
fix/read-buffer-128kib
Aug 15, 2026
Merged

Raise the response read buffer to 128KiB#150
MDA2AV merged 1 commit into
mainfrom
fix/read-buffer-128kib

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Aug 15, 2026

Copy link
Copy Markdown
Owner

RawTcpClient.ReadResponseAsync reads every response into a single fixed 64KiB buffer (new byte[65536]), and both the header loop and DrainAvailable are bounded by totalRead < buffer.Length. Anything beyond that is silently dropped — no exception, no truncation flag, just a short response that downstream assertions treat as the server's actual reply.

That bound is smaller than the largest request the suite sends.

What overruns it

Four tests build 100,000-byte payloads:

Test Payload
MAL-LONG-URL 100,000-char path
MAL-LONG-HEADER-NAME 100,000-char header name
MAL-LONG-HEADER-VALUE 100,000-char header value
MAL-LONG-METHOD 100,000-char method token

A server that echoes the offending value back in its error response — a reasonably common thing to do — produces a reply larger than 64KiB. The probe cuts it off and records the fragment. For those cases the result reflects our buffer, not the server's behaviour.

COOK-OVERSIZED and MAL-CHUNK-EXT-64K send exactly 65,536 bytes, so they sit right on the boundary and overrun as soon as any status line or headers accompany the echo.

Change

65536128 * 1024, extracted to a named ReadBufferSize constant with the ceiling documented next to it. 128KiB clears 100,000 bytes with ~30KiB of headroom for the status line and headers.

One buffer is allocated per ReadResponseAsync call, so this is +64KiB per read, transient and immediately collectable. No behavioural change for any response that already fit.

Verification

Builds clean in Release, 0 warnings / 0 errors.

Not yet run against live servers. The local hardware this was written on is mid-diagnosis for a suspected memory fault, so the full suite hasn't been executed to confirm the affected tests change verdict. The change is a pure bound increase — it can only make previously-truncated reads complete — but the CI probe run is the real check on whether any MAL-LONG-* result shifts.

ReadResponseAsync reads into a single fixed 64KiB buffer, and both the
header loop and DrainAvailable stop at buffer.Length. Anything past that
is silently dropped: no exception, no truncation flag, just a short
response that later assertions read as the server's actual reply.

Four tests send payloads of 100,000 bytes — MAL-LONG-URL,
MAL-LONG-HEADER-NAME, MAL-LONG-HEADER-VALUE and MAL-LONG-METHOD. A server
that echoes one back in its error response overruns the buffer, so what
the probe records for those cases is a truncation artifact rather than
what the server sent.

Raise the buffer to 128KiB, which clears the 100,000-byte ceiling with
room for status line and headers, and name it so the bound is documented
where the tests that set it are listed.
@sonarqubecloud

Copy link
Copy Markdown

@MDA2AV
MDA2AV merged commit 564021b into main Aug 15, 2026
1 of 2 checks passed
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