Skip to content

Commit aa4e264

Browse files
committed
fix(host_metrics source): use recv_from_full in fetch_netlink_inet_headers
1 parent 11aa135 commit aa4e264

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fixed tcp metrics collection in `host_metrics` source failing with "Could not parse netlink response: invalid netlink buffer" errors on Linux systems.
2+
3+
authors: mushrowan

src/sources/host_metrics/tcp.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,20 @@ async fn fetch_netlink_inet_headers(addr_family: u8) -> Result<Vec<InetResponseH
241241
.await
242242
.context(NetlinkSendSnafu)?;
243243

244-
let mut receive_buffer = vec![0; 4096];
245244
let mut inet_resp_hdrs = Vec::with_capacity(32); // Pre-allocate with an estimate
246245

247-
while let Ok(()) = socket.recv(&mut &mut receive_buffer[..]).await {
248-
let done = parse_netlink_messages(&receive_buffer, &mut inet_resp_hdrs)?;
249-
if done {
250-
break;
246+
loop {
247+
match socket.recv_from_full().await {
248+
Ok((receive_buffer, _addr)) => {
249+
if receive_buffer.is_empty() {
250+
break;
251+
}
252+
let done = parse_netlink_messages(&receive_buffer, &mut inet_resp_hdrs)?;
253+
if done {
254+
break;
255+
}
256+
}
257+
Err(_) => break,
251258
}
252259
}
253260

0 commit comments

Comments
 (0)