fix(client): validate blocking receive lifecycle before socket I/O
Rust CI / cargo fmt (push) Successful in 15s
Rust CI / cargo check (x86_64-unknown-linux-gnu) (push) Successful in 28s
Rust CI / cargo clippy (push) Successful in 31s
Rust CI / cargo check (x86_64-unknown-linux-musl) (push) Failing after 9s
Rust CI / cargo test (x86_64-unknown-linux-musl) (push) Failing after 10s
Rust CI / cargo doc (push) Successful in 23s
Rust CI / cargo test (x86_64-unknown-linux-gnu) (push) Successful in 1m10s
Fuzz Smoke / cargo fuzz smoke (push) Failing after 29s
Supply chain / cargo-deny advisories (push) Successful in 6s
Supply chain / cargo-deny bans licenses sources (push) Successful in 5s
Supply chain / actionlint (push) Successful in 3s
Netem Interop / netem interop (push) Successful in 59s
Rust CI / cargo fmt (push) Successful in 15s
Rust CI / cargo check (x86_64-unknown-linux-gnu) (push) Successful in 28s
Rust CI / cargo clippy (push) Successful in 31s
Rust CI / cargo check (x86_64-unknown-linux-musl) (push) Failing after 9s
Rust CI / cargo test (x86_64-unknown-linux-musl) (push) Failing after 10s
Rust CI / cargo doc (push) Successful in 23s
Rust CI / cargo test (x86_64-unknown-linux-gnu) (push) Successful in 1m10s
Fuzz Smoke / cargo fuzz smoke (push) Failing after 29s
Supply chain / cargo-deny advisories (push) Successful in 6s
Supply chain / cargo-deny bans licenses sources (push) Successful in 5s
Supply chain / actionlint (push) Successful in 3s
Netem Interop / netem interop (push) Successful in 59s
Blocking receives previously checked lifecycle only after a datagram arrived, allowing invalid operations to block or return empty success after timeout. Reuse session validation before socket access and cover connected, closed, and no-test-completed states through public APIs.
This commit is contained in:
5 files changed
+80
-4
No files matched your search
@@ -222,7 +222,9 @@ impl Client {
|
||||
///
|
||||
/// Returns an empty event list when the socket read would block or times
|
||||
/// out. Malformed or unrelated datagrams are reported as warning events.
|
||||
/// Requires an open session; lifecycle errors are returned before socket I/O.
|
||||
pub fn recv_once(&mut self) -> Result<Vec<ClientEvent>, ClientError> {
|
||||
self.runtime.ensure_open()?;
|
||||
self.socket
|
||||
.set_read_timeout(self.runtime.config().socket_config.recv_timeout)?;
|
||||
self.recv_once_inner()
|
||||
@@ -316,7 +318,10 @@ impl Client {
|
||||
|
||||
/// Receive and classify datagrams until a receive produces no events or the
|
||||
/// receive budget is exhausted.
|
||||
///
|
||||
/// Requires an open session; lifecycle errors are returned before socket I/O.
|
||||
pub fn recv_available(&mut self, budget: RecvBudget) -> Result<Vec<ClientEvent>, ClientError> {
|
||||
self.runtime.ensure_open()?;
|
||||
self.socket
|
||||
.set_read_timeout(self.runtime.config().socket_config.recv_timeout)?;
|
||||
let mut all_events = Vec::new();
|
||||
|
||||
@@ -591,7 +591,6 @@ impl SessionMachine {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
pub(crate) fn ensure_open(&self) -> Result<(), ClientError> {
|
||||
self.open_session().map(|_| ())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn open_fails_after_close() {
|
||||
fn operations_fail_after_local_close_without_datagrams() {
|
||||
let params = default_params();
|
||||
let server = start_fake_server(move |socket, tx| {
|
||||
let (_, peer) = recv_request(&socket, &tx);
|
||||
@@ -9,10 +9,26 @@ fn open_fails_after_close() {
|
||||
socket.send_to(&reply, peer).unwrap();
|
||||
let _ = recv_request(&socket, &tx);
|
||||
});
|
||||
let mut client = Client::connect(default_test_config(server.addr)).unwrap();
|
||||
let mut config = default_test_config(server.addr);
|
||||
config.socket_config.recv_timeout = Some(Duration::from_millis(50));
|
||||
let mut client = Client::connect(config).unwrap();
|
||||
assert_open_started(client.open().unwrap());
|
||||
client.close().unwrap();
|
||||
assert!(matches!(client.open(), Err(ClientError::AlreadyClosed)));
|
||||
let results = [
|
||||
client.recv_once(),
|
||||
client.recv_available(RecvBudget { max_packets: 1 }),
|
||||
];
|
||||
assert!(
|
||||
matches!(
|
||||
results,
|
||||
[
|
||||
Err(ClientError::AlreadyClosed),
|
||||
Err(ClientError::AlreadyClosed)
|
||||
]
|
||||
),
|
||||
"unexpected receive results: {results:?}"
|
||||
);
|
||||
server.join();
|
||||
}
|
||||
|
||||
@@ -473,6 +489,21 @@ fn close_flagged_echo_reply_emits_reply_then_closes_without_sending_close() {
|
||||
));
|
||||
assert_eq!(events.len(), 2);
|
||||
|
||||
let results = [
|
||||
client.recv_once(),
|
||||
client.recv_available(RecvBudget { max_packets: 1 }),
|
||||
];
|
||||
assert!(
|
||||
matches!(
|
||||
results,
|
||||
[
|
||||
Err(ClientError::AlreadyClosed),
|
||||
Err(ClientError::AlreadyClosed)
|
||||
]
|
||||
),
|
||||
"unexpected receive results: {results:?}"
|
||||
);
|
||||
|
||||
assert!(matches!(
|
||||
client.send_probe(),
|
||||
Err(ClientError::AlreadyClosed)
|
||||
|
||||
@@ -101,14 +101,29 @@ fn send_probe_fails_after_no_test_completed() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_fails_after_no_test_completed() {
|
||||
fn operations_fail_after_no_test_completed_without_datagrams() {
|
||||
let mut config = default_test_config(SocketAddr::from(([127, 0, 0, 1], 1)));
|
||||
config.run_mode = RunMode::NoTest;
|
||||
config.socket_config.recv_timeout = Some(Duration::from_millis(50));
|
||||
let params = default_params();
|
||||
let server = no_test_server(params, 0);
|
||||
config.server_addr = server.addr.to_string();
|
||||
let mut client = Client::connect(config).unwrap();
|
||||
assert_no_test_completed(client.open().unwrap());
|
||||
assert!(matches!(client.open(), Err(ClientError::AlreadyCompleted)));
|
||||
let results = [
|
||||
client.recv_once(),
|
||||
client.recv_available(RecvBudget { max_packets: 1 }),
|
||||
];
|
||||
assert!(
|
||||
matches!(
|
||||
results,
|
||||
[
|
||||
Err(ClientError::AlreadyCompleted),
|
||||
Err(ClientError::AlreadyCompleted)
|
||||
]
|
||||
),
|
||||
"unexpected receive results: {results:?}"
|
||||
);
|
||||
server.join();
|
||||
}
|
||||
@@ -1,5 +1,31 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn receive_before_open_returns_not_open_without_datagrams() {
|
||||
let peer = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
|
||||
let mut config = default_test_config(peer.local_addr().unwrap());
|
||||
// Bound the old implementation's blocking receive without sending a packet.
|
||||
config.socket_config.recv_timeout = Some(Duration::from_millis(50));
|
||||
let mut client = Client::connect(config).unwrap();
|
||||
|
||||
let results = [
|
||||
client.recv_once(),
|
||||
client.recv_available(RecvBudget { max_packets: 1 }),
|
||||
client.recv_available(RecvBudget { max_packets: 0 }),
|
||||
];
|
||||
assert!(
|
||||
matches!(
|
||||
results,
|
||||
[
|
||||
Err(ClientError::NotOpen),
|
||||
Err(ClientError::NotOpen),
|
||||
Err(ClientError::NotOpen)
|
||||
]
|
||||
),
|
||||
"unexpected receive results: {results:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// Untrusted returned intervals must be rejected before managed scheduling,
|
||||
// even when loose negotiation permits legitimate server restrictions.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user