limit the rate of streaming requests
Costa Tsaousis (ktsaou) committed
Jul 6, 2018 at 19:56 UTC
c8d2c1285aa05fcf0e3dd660a9f8f6cfa3a8d228
1 file changed
+15
src/rrdpush.c
+15
@@ -1111,6 +1111,21 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
1111
}
1112
}
1113
1114
+ {
1115
+ static netdata_mutex_t stream_rate_mutex = NETDATA_MUTEX_INITIALIZER;
1116
+ static volatile time_t last_stream_accepted_t = 0;
1117
+ time_t now = now_realtime_sec();
1118
+
1119
+ netdata_mutex_lock(&stream_rate_mutex);
1120
+ if(last_stream_accepted_t + 30 < now) {
1121
+ netdata_mutex_unlock(&stream_rate_mutex);
1122
+ error("STREAM [receive from [%s]:%s]: too busy to accept new streaming request. Try again in a while.", w->client_ip, w->client_port);
1123
+ return rrdpush_receiver_permission_denied(w);
1124
+ }
1125
+ last_stream_accepted_t = now;
1126
+ netdata_mutex_unlock(&stream_rate_mutex);
1127
+ }
1128
+
1129
struct rrdpush_thread *rpt = callocz(1, sizeof(struct rrdpush_thread));
1130
rpt->fd = w->ifd;
1131
rpt->key = strdupz(key);