fix(envoy-client): clear processed_command_idx after ack send#4812
Conversation
Code ReviewOverviewThis PR fixes a memory management issue in Correctness: Scope of the Clear is RightThe cleanup loop iterates
Race Condition (Acknowledged TODO)The TODO comment is accurate and well-written. The specific scenario:
The window is narrow (bytes in flight vs. FDB commit), but it exists. A proper fix would require an explicit ack-of-ack from Minor IssuesUnnecessary full-Vec clone ( last_command_checkpoints: last_command_checkpoints.clone(),The clone is needed because // Extract keys before consuming last_command_checkpoints
let keys_to_remove: Vec<(String, u32)> = last_command_checkpoints
.iter()
.map(|cp| (cp.actor_id.clone(), cp.generation))
.collect();
ws_send(
&ctx.shared,
protocol::ToRivet::ToRivetAckCommands(protocol::ToRivetAckCommands {
last_command_checkpoints, // moved, no clone
}),
)
.await;
for key in keys_to_remove {
ctx.processed_command_idx.remove(&key);
}This is semantically clearer (the original goes into the wire message) and avoids allocating a second copy of the Inner clone in the removal loop ( ctx.processed_command_idx.remove(&(cp.actor_id.clone(), cp.generation));
What's NOT Addressed (pre-existing)
Checklist
|

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: