summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2018-07-06 20:14:59 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2018-07-06 20:14:59 +0300
commitf5181aeb47350e996f951b5b6ae4b52a94d88dd5 (patch)
tree65d9de1a04081abb9c39e3a0cd3aa95e800c1e82 /src
parentc8d2c1285aa05fcf0e3dd660a9f8f6cfa3a8d228 (diff)
streaming rate limiting return error 503
Diffstat (limited to 'src')
-rw-r--r--src/rrdpush.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/rrdpush.c b/src/rrdpush.c
index 665e24b0ec..3f6a77fab3 100644
--- a/src/rrdpush.c
+++ b/src/rrdpush.c
@@ -1006,6 +1006,14 @@ int rrdpush_receiver_permission_denied(struct web_client *w) {
return 401;
}
+int rrdpush_receiver_too_busy_now(struct web_client *w) {
+ // we always respond with the same message and error code
+ // to prevent an attacker from gaining info about the error
+ buffer_flush(w->response.data);
+ buffer_sprintf(w->response.data, "The server is too busy now to accept this request. Try later.");
+ return 503;
+}
+
int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url) {
(void)host;
@@ -1117,11 +1125,15 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url
time_t now = now_realtime_sec();
netdata_mutex_lock(&stream_rate_mutex);
+ if(unlikely(last_stream_accepted_t == 0))
+ last_stream_accepted_t = now;
+
if(last_stream_accepted_t + 30 < now) {
netdata_mutex_unlock(&stream_rate_mutex);
- error("STREAM [receive from [%s]:%s]: too busy to accept new streaming request. Try again in a while.", w->client_ip, w->client_port);
- return rrdpush_receiver_permission_denied(w);
+ error("STREAM [receive from [%s]:%s]: too busy to accept new streaming request. Try again in %ld secs.", w->client_ip, w->client_port, (long)(last_stream_accepted_t + 30 - now));
+ return rrdpush_receiver_too_busy_now(w);
}
+
last_stream_accepted_t = now;
netdata_mutex_unlock(&stream_rate_mutex);
}