patches bug in recv_mmsg when npkts != nrecv (backport #22276) (#22280)

* removes total-size from return value of recv_mmsg

(cherry picked from commit 4b24499916)

* patches bug in recv_mmsg when npkts != nrecv

If recv_mmsg receives 2 packets where the first one is filtered out,
then it returns npkts == 1:
https://github.com/solana-labs/solana/blob/01a096adc/streamer/src/recvmmsg.rs#L104-L115

But then streamer::packet::recv_from will erroneously keep the 1st
packet and drop the 2nd one:
https://github.com/solana-labs/solana/blob/01a096adc/streamer/src/packet.rs#L34-L49

To avoid this bug, this commit updates recv_mmsg to always return total
number of received packets. If socket address cannot be correctly
obtained, it is left as the default value which is UNSPECIFIED:
https://github.com/solana-labs/solana/blob/01a096adc/sdk/src/packet.rs#L145

(cherry picked from commit 379feecae5)

Co-authored-by: behzad nouri <behzadnouri@gmail.com>
This commit is contained in:
mergify[bot]
2022-01-04 23:42:52 +00:00
committed by GitHub
parent f4ded6fb6b
commit fb0e5adc7e
5 changed files with 52 additions and 44 deletions

View File

@@ -2,7 +2,7 @@
use {
solana_streamer::{
packet::{Packet, PACKET_DATA_SIZE},
packet::{Meta, Packet, PACKET_DATA_SIZE},
recvmmsg::*,
},
std::{net::UdpSocket, time::Instant},
@@ -25,7 +25,7 @@ pub fn test_recv_mmsg_batch_size() {
}
let mut packets = vec![Packet::default(); TEST_BATCH_SIZE];
let now = Instant::now();
let recv = recv_mmsg(&reader, &mut packets[..]).unwrap().1;
let recv = recv_mmsg(&reader, &mut packets[..]).unwrap();
elapsed_in_max_batch += now.elapsed().as_nanos();
assert_eq!(TEST_BATCH_SIZE, recv);
});
@@ -40,10 +40,13 @@ pub fn test_recv_mmsg_batch_size() {
let mut recv = 0;
let now = Instant::now();
while let Ok(num) = recv_mmsg(&reader, &mut packets[..]) {
recv += num.1;
recv += num;
if recv >= TEST_BATCH_SIZE {
break;
}
packets
.iter_mut()
.for_each(|pkt| pkt.meta = Meta::default());
}
elapsed_in_small_batch += now.elapsed().as_nanos();
assert_eq!(TEST_BATCH_SIZE, recv);