Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discards packets which are not (fully) populated #3508

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

behzadnouri
Copy link

Problem

Not discarding packets which are not (fully) populated is bug prone or might waste resources.

Summary of Changes

Discard packets which are not (fully) populated.

Not discarding packets which are not (fully) populated is bug prone or
might waste resources.
@@ -90,9 +90,11 @@ impl PacketBatch {
// break the payload into smaller messages, and here any errors
// should be propagated.
error!("Couldn't write to packet {:?}. Data skipped.", e);
packet.meta_mut().set_discard(true);
Copy link

Choose a reason for hiding this comment

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

Idea makes sense, what do you think about moving line inside Packet::populate_packet so that we get this behavior across the board, not just from this one PacketBatch constructor ?

Copy link
Author

Choose a reason for hiding this comment

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

I would rather not do that.
If there is a failure, Packet::populate_packet is returning the error to the caller. The caller may choose to either:

  1. discard the packet (like in this commit).
  2. or, reuse the packet and write the next payload to it. In which case it shouldn't be marked discard.

The problem with the current code is that the caller is effectively ignoring the error.

Copy link

Choose a reason for hiding this comment

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

or, reuse the packet and write the next payload to it. In which case it shouldn't be marked discard.

Sure, but if the caller is making a conscious decision to "recycle" the packet, it doesn't seem unreasonable to call .set_discard(false) to clean up this "dirtied" packet

Copy link

@steviez steviez left a comment

Choose a reason for hiding this comment

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

I'm fine with this as-is; I'm probably lacking some context for the situation you have in mind.

On a related note, I'm currently working on a change to clean this up:

agave/sdk/packet/src/lib.rs

Lines 210 to 213 in 966c3c8

#[allow(clippy::uninit_assumed_init)]
impl Default for Packet {
fn default() -> Self {
let buffer = std::mem::MaybeUninit::<[u8; PACKET_DATA_SIZE]>::uninit();

As part of that work, I'll likely be reviewing the various places packets are created & populated, so we can revisit incase I develop a stronger opinion on this

@@ -90,9 +90,11 @@ impl PacketBatch {
// break the payload into smaller messages, and here any errors
// should be propagated.
error!("Couldn't write to packet {:?}. Data skipped.", e);
packet.meta_mut().set_discard(true);
Copy link

Choose a reason for hiding this comment

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

or, reuse the packet and write the next payload to it. In which case it shouldn't be marked discard.

Sure, but if the caller is making a conscious decision to "recycle" the packet, it doesn't seem unreasonable to call .set_discard(false) to clean up this "dirtied" packet

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