Skip to content

Commit

Permalink
Fix max udp size bug
Browse files Browse the repository at this point in the history
The buffer length counting was incorrect, and for large pipelines the
65k the entire packet will be dropped

Fixes #30
  • Loading branch information
markstory committed Oct 30, 2024
1 parent 1094ea6 commit 2a71ee6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl error::Error for StatsdError {}
///
/// # Example
///
/// Creating a client and sending metrics is easy.
/// Creating a client and sending metrics can be done with:
///
/// ```ignore
/// use statsd::client::Client;
Expand Down Expand Up @@ -415,7 +415,7 @@ impl Pipeline {
_data += client.prepare(&data).as_ref();
while !self.stats.is_empty() {
let stat = client.prepare(self.stats.pop_front().unwrap());
if data.len() + stat.len() + 1 > self.max_udp_size {
if _data.len() + stat.len() + 1 > self.max_udp_size {
client.send(_data.clone());
_data.clear();
_data += &stat;
Expand Down Expand Up @@ -679,6 +679,20 @@ mod test {
assert_eq!(vec!["myapp.metric:9.1|g", "myapp.metric:12.2|c"], response);
}

#[test]
fn test_pipeline_set_max_udp_size_chunk() {
let server = Server::new();
let client = Client::new(server.addr(), "myapp").unwrap();
let response = server.run_while_receiving_all(|| {
let mut pipeline = client.pipeline();
pipeline.set_max_udp_size(5);
pipeline.gauge("metric_gauge", 9.1);
pipeline.count("metric_letters", 12.2);
pipeline.send(&client);
});
assert_eq!(vec!["myapp.metric_gauge:9.1|g", "myapp.metric_letters:12.2|c"], response);
}

#[test]
fn test_pipeline_send_metric_after_pipeline() {
let server = Server::new();
Expand Down

0 comments on commit 2a71ee6

Please sign in to comment.