{"record":{"id":"7127df3e40a3be9b","repo":"apache/cassandra","slug":"user-defined-function-s-ran-longer-than-dms","errorCode":null,"errorMessage":"User defined function %s ran longer than %dms","messagePattern":"User defined function (.+?) ran longer than (.+?)ms","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/cql3/functions/UDFunction.java","lineNumber":512,"sourceCode":"    }\n\n    private <T> T async(ThreadIdAndCpuTime threadIdAndCpuTime, Callable<T> callable)\n    {\n        Future<T> future = executor().submit(callable);\n\n        try\n        {\n            if (DatabaseDescriptor.getUserDefinedFunctionWarnTimeout() > 0)\n                try\n                {\n                    return future.get(DatabaseDescriptor.getUserDefinedFunctionWarnTimeout(), TimeUnit.MILLISECONDS);\n                }\n                catch (TimeoutException e)\n                {\n\n                    // log and emit a warning that UDF execution took long\n                    String warn = String.format(\"User defined function %s ran longer than %dms\", this, DatabaseDescriptor.getUserDefinedFunctionWarnTimeout());\n                    logger.warn(warn);\n                    ClientWarn.instance.warn(warn);\n                }\n\n            // retry with difference of warn-timeout to fail-timeout\n            return future.get(DatabaseDescriptor.getUserDefinedFunctionFailTimeout() - DatabaseDescriptor.getUserDefinedFunctionWarnTimeout(), TimeUnit.MILLISECONDS);\n        }\n        catch (InterruptedException e)\n        {\n            Thread.currentThread().interrupt();\n            throw new UncheckedInterruptedException(e);\n        }\n        catch (ExecutionException e)\n        {\n            Throwable c = e.getCause();\n            if (c instanceof RuntimeException)\n                throw (RuntimeException) c;\n            throw new RuntimeException(c);\n        }","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/UDFunction.java#L494-L530","documentation":"UDFunction.async logs a warning (and warns the client via ClientWarn) when a user-defined function execution exceeds user_defined_function_warn_timeout milliseconds. Execution is NOT aborted: after warning, the call waits the remaining warn-to-fail window before enforcing the fail timeout.","triggerScenarios":"A UDF's future.get() times out at getUserDefinedFunctionWarnTimeout(); invoked via executeAsync or executeAggregateAsync when running a SELECT containing the UDF.","commonSituations":"UDFs doing expensive per-row computation (regex, crypto, large JSON parsing); JVM pauses; slow sandboxed code on large cells.","solutions":["Optimize or simplify the UDF body","Raise user_defined_function_warn_timeout in cassandra.yaml if the runtime is expected","Precompute/filter rows before applying the UDF to reduce invocations"],"exampleFix":"# cassandra.yaml\n# before\nuser_defined_function_warn_timeout: 500\n# after\nuser_defined_function_warn_timeout: 5000","handlingStrategy":"validation","validationCode":"// Pre-deploy: benchmark the UDF on representative data\nlong t0 = System.nanoTime(); udf.call(sampleInput); long ms = (System.nanoTime()-t0)/1_000_000;\nif (ms > warnTimeout) throw new IllegalStateException(\"UDF too slow: \" + ms + \"ms\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep UDF bodies trivial (pure, in-memory, constant-time per row)","Benchmark UDFs against worst-case cell sizes before deploying","Review user_defined_function_warn_timeout/fail_timeout settings when tuning"],"tags":["udf","timeout","performance"],"backgroundTag":"request-timeout","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}