Skip to content

Infinite unbound loop in analytics processor lead to 100% CPU usage #55

Description

@Totodore

The following code loops indefinitely without pause, this leads to 100% CPU usage in all our environment (dev/qual/prod). We disabled the analytics processor in the meantime.

Solution

Use rx.recv_timeout rather than try_recv which is non blocking.

.spawn(move || {
let mut last_flushed = chrono::Utc::now();
loop {
let data = rx.try_recv();
let mut analytics_data = analytics_data_locked.write().unwrap();
match data {
// Update the analytics data with feature_id received
Ok(feature_name) => {
analytics_data
.entry(feature_name)
.and_modify(|e| *e += 1)
.or_insert(1);
}
Err(flume::TryRecvError::Empty) => {}
Err(flume::TryRecvError::Disconnected) => {
debug!("Shutting down analytics thread ");
break;
}
};
if (chrono::Utc::now() - last_flushed).num_milliseconds() > timer as i64 {
flush(&client, &analytics_data, &analytics_endpoint);
analytics_data.clear();
last_flushed = chrono::Utc::now();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions