The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Prevent an analytics configuration error to shadow the timeout (#77098)
metamben87fabef5e3e9
diff --git a/src/metabase/sql_parsing/graal.clj b/src/metabase/sql_parsing/graal.cljindex 1b25e4db894..81716e8ec4f 100644--- a/src/metabase/sql_parsing/graal.clj+++ b/src/metabase/sql_parsing/graal.clj@@ -239,8 +239,11 @@;; future-cancel doesn't stop GraalVM execution, so interrupt the context itself;; (1s grace period for the soft interrupt)(interrupt! context 1000)- (analytics/inc! :metabase-sql-parsing/context-timeouts)(log/warn "Python execution timed out after" call-timeout-ms "ms - GraalVM interrupted")+ ;; Best-effort metric bump: a misconfigured registry must not mask the timeout (#77084).+ (try (analytics/inc! :metabase-sql-parsing/context-timeouts)+ (catch Throwable e+ (log/warn e "Failed to increment :metabase-sql-parsing/context-timeouts")))(throw (TimeoutException. (str "Python execution timed out after " call-timeout-ms "ms"))))result))(finallydiff --git a/test/metabase/sql_parsing/core_test.clj b/test/metabase/sql_parsing/core_test.cljindex 27dd4ac3f35..54c36f9544c 100644--- a/test/metabase/sql_parsing/core_test.clj+++ b/test/metabase/sql_parsing/core_test.clj@@ -3,8 +3,12 @@[clojure.java.io :as io][clojure.string :as str][clojure.test :refer :all]+ [metabase.analytics-interface.core :as analytics-interface][metabase.sql-parsing.core :as sql-parsing]- [metabase.util :as u]))+ [metabase.sql-parsing.graal :as graal]+ [metabase.util :as u])+ (:import+ (java.util.concurrent TimeoutException)))(set! *warn-on-reflection* true)@@ -805,3 +809,18 @@(sql-parsing/referenced-tables "postgres" "SELECT !!!")(catch Exception e e))](is (sql-parsing/parse-error? e)))))++;;; ------------------------------------------------ Timeout robustness --------------------------------------------++(deftest timeout-surfaces-even-when-metric-inc-fails-test+ (testing (str "A fired Python-call timeout still surfaces as TimeoutException from the API even if "+ "the timeout-metric bump throws — a misconfigured analytics registry must not shadow "+ "the timeout (#77084).")+ (with-redefs [;; force the timeout branch of do-with-python-context without waiting 30s+ graal/with-timeout* (fn [_ _] :metabase.sql-parsing.graal/timeout)+ ;; poison only the timeout metric; leave the acquisition inc! alone+ analytics-interface/inc! (fn [k & _]+ (when (= k :metabase-sql-parsing/context-timeouts)+ (throw (Exception. "boom"))))]+ (is (thrown? TimeoutException+ (sql-parsing/referenced-tables "postgres" "SELECT 1"))))))