Skip to content

Abort broken connections instead of closing them - #530

Merged
Dreamsorcerer merged 3 commits into
aio-libs:masterfrom
RayBB:fix/abort-broken-connections
Nov 24, 2026
Merged

Dreamsorcerer merged 3 commits into
aio-libs:masterfrom
RayBB:fix/abort-broken-connections

Conversation

@RayBB

@RayBB RayBB commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

When a command times out or is cancelled, part of it can still be in the transport's write buffer. release(broken=True) called writer.close(), which sends that buffer before closing. memcached could then carry out a set() after the caller had already got TimeoutError, and the socket stayed open beyond its pool slot until the flush finished. With the timeout option, any slow write that times out can hit this.

Close broken connections with transport.abort() instead, which drops the buffer. clear() still closes idle connections gracefully. The new test times out a 16 MB set() against a server that isn't reading yet, then checks that the server doesn't receive the whole value. On master the server receives all of it.

A command that times out or is cancelled can leave part of itself in
the transport's write buffer. release(broken=True) closed the writer,
which sends that buffer before closing, so memcached could still carry
out a set() after the caller got TimeoutError, and the socket outlived
its pool slot until the flush finished. Abort the transport instead so
the buffered data is dropped. clear() still closes idle connections
gracefully.
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.37%. Comparing base (010ee63) to head (7f9a106).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #530      +/-   ##
==========================================
+ Coverage   97.97%   98.37%   +0.39%     
==========================================
  Files          10       10              
  Lines        1037     1229     +192     
  Branches       57       65       +8     
==========================================
+ Hits         1016     1209     +193     
  Misses         12       12              
+ Partials        9        8       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge.

Reviews (3) · Last reviewed commit: "Update aiomcache/pool.py" · Reviewed by Greptile

Comment thread tests/pool_test.py Resolved
Otherwise the deadline could expire before set() wrote anything, and the
test would pass even with a graceful close.
Comment thread aiomcache/pool.py Resolved
@Dreamsorcerer
Dreamsorcerer merged commit 4fae7e8 into aio-libs:master Nov 24, 2026
14 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.

2 participants