From 6a0fe665f04eeebcd9b4928fc7082ff477cb4e1b Mon Sep 17 00:00:00 2001 From: Dhawal Sanghvi Date: Thu, 13 Jun 2024 04:00:14 +0530 Subject: [PATCH] feat: metrics aggregator - reject new request if a request is already being processed --- src/util/metricsAggregator.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/metricsAggregator.js b/src/util/metricsAggregator.js index 7cbb47256b..bb46db37a9 100644 --- a/src/util/metricsAggregator.js +++ b/src/util/metricsAggregator.js @@ -72,6 +72,16 @@ class MetricsAggregator { } async aggregateMetrics() { + // If a request is already being processed, reject the new request + // Use resolveFunc to check if a request is already being processed + if (this.resolveFunc !== null) { + logger.error( + '[MetricsAggregator] Failed to serve /metrics request, a request is already being processed.', + ); + throw new Error( + '[MetricsAggregator] Currently processing a request, please try again later.', + ); + } return new Promise((resolve, reject) => { this.resolveFunc = resolve; this.rejectFunc = reject;