Skip to content

connection: release request ids after failed sends#874

Open
dkropachev wants to merge 3 commits intoscylladb:masterfrom
dkropachev:dk/connection-send-failure-cleanup
Open

connection: release request ids after failed sends#874
dkropachev wants to merge 3 commits intoscylladb:masterfrom
dkropachev:dk/connection-send-failure-cleanup

Conversation

@dkropachev
Copy link
Copy Markdown
Collaborator

Fixes #873. Reclaims request ids when send_msg fails and covers the async keyspace path with unit tests.

@dkropachev dkropachev force-pushed the dk/connection-send-failure-cleanup branch from 32e8008 to 856efaa Compare May 7, 2026 06:48
@dkropachev dkropachev self-assigned this May 7, 2026
Comment thread cassandra/connection.py
Comment on lines 1222 to 1279
@@ -1262,9 +1266,16 @@ def wait_for_responses(self, *msgs, **kwargs):
self.in_flight += available

for i, request_id in enumerate(request_ids):
self.send_msg(msgs[messages_sent + i],
request_id,
partial(waiter.got_response, index=messages_sent + i))
try:
self.send_msg(msgs[messages_sent + i],
request_id,
partial(waiter.got_response, index=messages_sent + i))
except Exception:
unsent_request_ids = request_ids[i:]
with self.lock:
self.in_flight -= len(unsent_request_ids)
self.request_ids.extend(unsent_request_ids)
raise
messages_sent += available
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are now multiple PRs regarding request_ids, in_flight etc.
It is incredible that we need to ever worry about this stuff.
Why is it even responsibility of the caller to adjust those values?
Connection should have a method for sending request. This method should be responsible for managing in_flight, request_ids and other state of Connection. Callers should never worry about that.

This is the only sane solution, and anything else will just require fixing callsites forever.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes I know this is a code in connection. But you also have PRs for e.g. hearbeats. Heartbeats should never need to touch this stuff.

Copy link
Copy Markdown
Collaborator Author

@dkropachev dkropachev May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged. I removed the async keyspace cleanup from this branch, so this PR is now scoped to the concrete send-failure leak only. The broader connection-level helper/refactor can stay as a separate follow-up.

@dkropachev dkropachev marked this pull request as ready for review May 8, 2026 02:55
@dkropachev dkropachev requested a review from Lorak-mmk May 8, 2026 02:55
@Lorak-mmk
Copy link
Copy Markdown

As I said on the hearbeat PR - maybe the send_msg should clean this up?

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.

connection: release request ids after failed sends

2 participants