Skip to content

make sure to unset batch_key when connection is removed from batch#48311

Merged
jkarneges merged 2 commits intomainfrom
jkarneges/batch-fix
Mar 25, 2026
Merged

make sure to unset batch_key when connection is removed from batch#48311
jkarneges merged 2 commits intomainfrom
jkarneges/batch-fix

Conversation

@jkarneges
Copy link
Copy Markdown
Member

For bulk IPC communication, Pushpin will address multiple connections in the same packet. For example, if a component needs to send keep-alive packets for 100 connections with a peer, then it will try to send just 1 keep-alive packet to that peer that is addressed to all 100 connections.

In connmgr, the Batch type helps sort out how to do this. When it is time to perform such bulk communications, connections are added to the batch with Batch::add, even if the connections are with different peers. Then, peer-specific "groups" of connections can be extracted with Batch::take_group for easily sending to them.

When a ConnectionItem is added to a batch, its batch_key field will be set to the return value of Batch::add. This value is kept around so if the connection is dropped it can remove itself from the batch with Batch::remove. Importantly, when the connection has been removed from the batch via Batch::take_group, this field needs to be set to None. In some very rare cases we might fail to do this, which means when the connection is eventually dropped it will try to remove itself from a batch that it's not in. This will result in a panic in List::remove().

Those rare cases we fail to unset batch_key are:

  • If the closure provided to take_group returns None. In this case, the connection will still be removed from the batch without this being communicated to the caller, and so the caller doesn't know to unset the batch_key.
  • If the caller errors out in some way between the time take_group returns and when it unsets batch_key.

This PR makes the batch API a little more clear and ensures batch_key is always set to None for connections removed by take_group.

@jkarneges jkarneges force-pushed the jkarneges/batch-fix branch 5 times, most recently from 9e808ef to 6258d7d Compare March 20, 2026 21:49
@jkarneges jkarneges changed the title ensure to unset batch_key when connection is removed from batch make sure to unset batch_key when connection is removed from batch Mar 20, 2026
@jkarneges jkarneges force-pushed the jkarneges/batch-fix branch from 6258d7d to 0f5ebb6 Compare March 21, 2026 21:17
@jkarneges jkarneges requested a review from a team March 23, 2026 17:35
@jkarneges jkarneges merged commit 019b9d9 into main Mar 25, 2026
19 checks passed
@jkarneges jkarneges deleted the jkarneges/batch-fix branch March 25, 2026 17:06
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