From 7cfb809af4686f4663e9531a0f6aba76e8fb8f4b Mon Sep 17 00:00:00 2001 From: Jonathan Creasy Date: Mon, 26 Oct 2020 16:42:29 -0400 Subject: [PATCH] Re-introduce query timeouts. (#2035) Co-authored-by: Itamar Turner-Trauring --- src/core/SaltScanner.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/SaltScanner.java b/src/core/SaltScanner.java index d7ef54117..a17524b85 100644 --- a/src/core/SaltScanner.java +++ b/src/core/SaltScanner.java @@ -491,7 +491,8 @@ final class ScannerCB implements Callback> rows) final List> lookups = filters != null && !filters.isEmpty() ? new ArrayList>(rows.size()) : null; - + + // fail the query when the timeout exceeded + if (this.query_timeout > 0 && fetch_time > (this.query_timeout * 1000000)) { + try { + close(false); + handleException( + new QueryException(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, + "Sorry, your query timed out. Time limit: " + + this.query_timeout + " ms, fetch time: " + + (double)(fetch_time)/1000000 + " ms. Please try filtering " + + "using more tags or decrease your time range.")); + return false; + } catch (Exception e) { + LOG.error("Sorry, Scanner is closed: " + scanner, e); + return false; + } + } + // validation checking before processing the next set of results. It's // kinda funky but we want to allow queries to sneak through that were // just a *tad* over the limits so that's why we don't check at the