hanke580 opened a new issue, #71181: URL: https://github.com/apache/doris/issues/71181
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version - master `b4140d0b0538` (2026-11-30), built from source: `select @@version_comment` = `doris version doris-0.0.0-b4140d0b05` - doris-4.1.5-release-917b20be838 (`apache/doris:fe-4.1.5` and `apache/doris:be-4.1.5`, one FE and one BE) ### What's Wrong? The FE folds a constant `repeat(str, n)` itself only when the result is small. The check multiplies the string length by the count in Java `int`, and the product wraps. For `repeat('ab', 1073741824)` it is 2^31, which wraps to -2147483648, and for `repeat('%l', 2147483647)` it is 2 * (2^31 - 1), which wraps to -2. Both are below the limit, so the FE starts building a string of 2^31 or more characters. Its heap fills up until `java.lang.OutOfMemoryError: Requested array size exceeds VM limit`, and `-XX:OnOutOfMemoryError="kill -9 %p"` (added by `start_fe.sh`) kills the FE. A single `SELECT` from any user takes the FE down. Without a restart policy it stays down, and it leaves a heap dump of several GB in the log directory. On 4.1.5: ``` mysql> SELECT date_format('2022-11-13 11:12:12', repeat('%l', 2147483647)); ERROR 2013 (HY000): Lost connection to MySQL server during query ``` fe.out: ``` java.lang.OutOfMemoryError: Requested array size exceeds VM limit Dumping heap to /opt/apache-doris/fe/log/java_pid579.hprof ... Heap dump file created [4629313378 bytes in 10.020 secs] # # java.lang.OutOfMemoryError: Requested array size exceeds VM limit # -XX:OnOutOfMemoryError="kill -9 %p" # Executing /bin/sh -c "kill -9 579"... ``` and the FE container exited with status 137. The GC log before it shows humongous allocations growing the heap (`Pause Young (Concurrent Start) (G1 Humongous Allocation) 4381M->2201M(8192M)`). On master the same two statements end the same way: the `date_format` one lost its connection after 49 s and `SELECT repeat('ab', 1073741824)` after 48 s, each with the same `OutOfMemoryError` and `kill -9` in fe.out (heap dumps of 4.6 GB). The per-query memory limit does not prevent it: with `SET exec_mem_limit = 104857600` (100 MB) on master, `SELECT repeat('ab', 1073741824)` still killed the FE after 50 s, with the same `OutOfMemoryError`. The folding runs in the FE's JVM, before any BE limit applies. Below the wrap the check works: `EXPLAIN SELECT repeat('%l', 400000)` shows the folded string, and `EXPLAIN SELECT repeat('%l', 600000)` leaves `repeat('%l', 600000)` to the BE. The check is in `StringArithmetic.repeat()`, `fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java` ([master, lines 736-746](https://github.com/apache/doris/blob/b4140d0b0538f5bf2acedcf8aa7a4d664bbb4927/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/StringArithmetic.java#L736-L746)): ```java @ExecFunction(name = "repeat") public static Expression repeat(StringLikeLiteral first, IntegerLiteral second) { // when it is too large for fe to make result string, do not folding on fe, limit 1 MB if ((first.getValue().length() * second.getValue()) > 1000000) { throw new AnalysisException("repeat too large to fold const by fe"); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < second.getValue(); i++) { sb.append(first.getValue()); } ``` `length()` and `getValue()` are both `int`. ### What You Expected? The FE does not fold these calls, as for `repeat('%l', 600000)`, and leaves them to the BE, which checks the size. With folding disabled (`SET debug_skip_fold_constant = true`), 4.1.5 answers `SELECT str_to_map(repeat('a:1,', 2147483647))` with `[E-3113]string column length is too large: total_length=8589934588, element_number=0, rows=0`, and the FE stays up. No statement should be able to kill the FE. ### How to Reproduce? One FE and one BE with default settings. **Each of the last two statements kills the FE**; run them on a cluster of your own and restart the FE between them. ```sql EXPLAIN SELECT repeat('%l', 400000); -- folded by the FE EXPLAIN SELECT repeat('%l', 600000); -- left to the BE SELECT repeat('ab', 1073741824); -- 2 * 2^30 wraps to -2^31: the FE folds it and dies SELECT date_format('2022-11-13 11:12:12', repeat('%l', 2147483647)); -- 2 * (2^31 - 1) wraps to -2 ``` ### Anything Else? Computing the product in `long`, for example `if ((long) first.getValue().length() * second.getValue() > 1000000)`, keeps the check from wrapping. `StringArithmetic.space()` compares its count directly (`first.getValue() > 1000000`) and is not affected. ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
