Skip to content

Commit 2a71ee6

Browse files
committed
Fix max udp size bug
The buffer length counting was incorrect, and for large pipelines the 65k the entire packet will be dropped Fixes #30
1 parent 1094ea6 commit 2a71ee6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/client.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl error::Error for StatsdError {}
4242
///
4343
/// # Example
4444
///
45-
/// Creating a client and sending metrics is easy.
45+
/// Creating a client and sending metrics can be done with:
4646
///
4747
/// ```ignore
4848
/// use statsd::client::Client;
@@ -415,7 +415,7 @@ impl Pipeline {
415415
_data += client.prepare(&data).as_ref();
416416
while !self.stats.is_empty() {
417417
let stat = client.prepare(self.stats.pop_front().unwrap());
418-
if data.len() + stat.len() + 1 > self.max_udp_size {
418+
if _data.len() + stat.len() + 1 > self.max_udp_size {
419419
client.send(_data.clone());
420420
_data.clear();
421421
_data += &stat;
@@ -679,6 +679,20 @@ mod test {
679679
assert_eq!(vec!["myapp.metric:9.1|g", "myapp.metric:12.2|c"], response);
680680
}
681681

682+
#[test]
683+
fn test_pipeline_set_max_udp_size_chunk() {
684+
let server = Server::new();
685+
let client = Client::new(server.addr(), "myapp").unwrap();
686+
let response = server.run_while_receiving_all(|| {
687+
let mut pipeline = client.pipeline();
688+
pipeline.set_max_udp_size(5);
689+
pipeline.gauge("metric_gauge", 9.1);
690+
pipeline.count("metric_letters", 12.2);
691+
pipeline.send(&client);
692+
});
693+
assert_eq!(vec!["myapp.metric_gauge:9.1|g", "myapp.metric_letters:12.2|c"], response);
694+
}
695+
682696
#[test]
683697
fn test_pipeline_send_metric_after_pipeline() {
684698
let server = Server::new();

0 commit comments

Comments
 (0)