Skip to content

Drain rejected webhook bodies before closing to avoid TCP RST on Windows#190

Merged
JE-Chen merged 1 commit into
mainfrom
dev
May 21, 2026
Merged

Drain rejected webhook bodies before closing to avoid TCP RST on Windows#190
JE-Chen merged 1 commit into
mainfrom
dev

Conversation

@JE-Chen
Copy link
Copy Markdown
Member

@JE-Chen JE-Chen commented May 21, 2026

Summary

Follow-up to PR #189. The headless test suite intermittently failed on Windows CI runners at test_webhook_trigger.py::test_oversize_body_rejected with WinError 10053 (connection aborted) — masking the 4xx status the test was actually asserting.

Root cause: _WebhookHandler._read_body() sent 413 Request Entity Too Large and returned with the request body still buffered in the receive socket. Windows TCP turns close() with unread bytes into RST (not FIN), so the client got an aborted-connection error before it could read the 413 response.

Fix: a new _reject_with_drain(status, message, length) helper sends the 4xx, then discards up to min(length, 4 × _MAX_BODY_BYTES) bytes from rfile in 64 KiB chunks before the socket closes — clean FIN, response delivered. Applied to all three early-return paths in _dispatch (404 / 401 / 413). The 4× cap stops a hostile Content-Length: 9999999999 from making the server spin.

Test plan

The previous flow sent the 4xx response (413/404/401) and let the
socket close with the request body still buffered. Windows TCP turns
close-with-unread-bytes into RST, which the client surfaces as
WinError 10053 *before* the response is read — masking the status and
intermittently flaking test_oversize_body_rejected on CI runners.

Now every early-return path drains the declared body in 64 KiB chunks
(capped at 4× the body limit so a hostile Content-Length can't make
us spin), guaranteeing a clean FIN close and a readable 4xx on the
client side.
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@sonarqubecloud
Copy link
Copy Markdown

@JE-Chen JE-Chen merged commit 9d91e3d into main May 21, 2026
27 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