已合并
fix: 修复 gen_esb ASAN重试盲区与脚本缓存陈旧问题(#466) #3725
fix: 修复 gen_esb ASAN重试盲区与脚本缓存陈旧问题(#466) #3725
已合并
GengChao创建于 6月25日
共 1 个文件变更+17-2
@@ -173,7 +173,7 @@ endmacro()
173 173 
174function(_add_es_library_impl)174function(_add_es_library_impl)
175 # 0. 生成辅助 shell 脚本(自包含,无需外部文件)175 # 0. 生成辅助 shell 脚本(自包含,无需外部文件)
176- # 在首次调用时创建 run_gen_esb_with_lock.sh 到构建目录176+ # 每次 cmake 配置都重新生成 run_gen_esb_with_lock.sh(确保 ENABLE_ASAN 等变化即时生效)
177 set(ES_LOCK_SCRIPT "${CMAKE_BINARY_DIR}/cmake/run_gen_esb_with_lock.sh")177 set(ES_LOCK_SCRIPT "${CMAKE_BINARY_DIR}/cmake/run_gen_esb_with_lock.sh")
178 # 将 ENABLE_ASAN 归一化为 "true" 或空字符串178 # 将 ENABLE_ASAN 归一化为 "true" 或空字符串
179 # CMake if() 自动识别 TRUE/True/ON/On/on/YES/yes/1 等真值,无需逐一枚举179 # CMake if() 自动识别 TRUE/True/ON/On/on/YES/yes/1 等真值,无需逐一枚举
@@ -182,7 +182,12 @@ function(_add_es_library_impl)
182 else()182 else()
183 set(ENABLE_ASAN_NORMALIZED "")183 set(ENABLE_ASAN_NORMALIZED "")
184 endif()184 endif()
185- if (NOT EXISTS ${ES_LOCK_SCRIPT})185+ # 每次 cmake 配置都重新生成脚本,确保 ENABLE_ASAN 等配置变化能即时反映到脚本中
186+ # (修复脚本缓存陈旧导致 --asan=false 不生效的问题,见 issue #466)。
187+ # 使用 GLOBAL property 避免同一 cmake 进程内多 ES package 调用时重复生成;
188+ # GLOBAL property 不写入 CMakeCache.txt,每次 cmake 进程都会重新生成。
189+ get_property(_ES_LOCK_SCRIPT_GENERATED GLOBAL PROPERTY _ES_LOCK_SCRIPT_GENERATED SET)
190+ if (NOT _ES_LOCK_SCRIPT_GENERATED)
186 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/cmake")191 file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/cmake")
187 file(WRITE ${ES_LOCK_SCRIPT} "#!/bin/bash192 file(WRITE ${ES_LOCK_SCRIPT} "#!/bin/bash
188# Copyright (c) 2025 Huawei Technologies Co., Ltd.193# Copyright (c) 2025 Huawei Technologies Co., Ltd.
@@ -306,6 +311,11 @@ execute_gen_esb() {
306 sleep 0.5311 sleep 0.5
307 sync312 sync
308 RETRY_COUNT=\$((RETRY_COUNT + 1))313 RETRY_COUNT=\$((RETRY_COUNT + 1))
314+ elif [[ \"${ENABLE_ASAN_NORMALIZED}\" == \"true\" ]] && [ \$EXIT_CODE -eq 1 ]; then
315+ log_debug \"[Retriable] Exit code 1 under ASan (likely nested bug or shadow-memory conflict), retrying...\"
316+ sleep 0.5
317+ sync
318+ RETRY_COUNT=\$((RETRY_COUNT + 1))
309 else319 else
310 log_debug \"[Non-retriable] Exit code \$EXIT_CODE\"320 log_debug \"[Non-retriable] Exit code \$EXIT_CODE\"
311 return \$EXIT_CODE321 return \$EXIT_CODE
@@ -313,6 +323,10 @@ execute_gen_esb() {
313 fi323 fi
314 done324 done
315 log_debug \"[Final Failure] Reached maximum retry count \$MAX_RETRIES\"325 log_debug \"[Final Failure] Reached maximum retry count \$MAX_RETRIES\"
326+ if [[ \"${ENABLE_ASAN_NORMALIZED}\" == \"true\" ]]; then
327+ log_debug \"[Hint] ASan is enabled. If this reproduces consistently, gen_esb may have a real memory defect;\"
328+ log_debug \" re-run with --asan=false (after removing the cached run_gen_esb_with_lock.sh) to confirm.\"
atomgit-bot
atomgit-botatomgit-bot6月25日

🔵 Low Priority

变更行:第 328 行(生成的 shell 脚本内容)。 本次修复将脚本生成条件从 if (NOT EXISTS ${ES_LOCK_SCRIPT}) 改为基于 GLOBAL property 的每 cmake 进程一次生成(第 185-190 行),使得脚本在每次 cmake 配置时都会重新生成,不再存在"脚本缓存陈旧"的问题。

建议:移除括号中的 "(after removing the cached run_gen_esb_with_lock.sh)",或改为提示用户需要重新执行 cmake 配置让脚本重新生成。

改动建议
328
- log_debug \" re-run with --asan=false (after removing the cached run_gen_esb_with_lock.sh) to confirm.\"
328
+ log_debug \" re-run with --asan=false (re-run cmake to regenerate this script) to confirm.\"
应用建议
likedislike
不准确?
329+ fi
316 return 1330 return 1
317}331}
318 332 
@@ -401,6 +415,7 @@ exit 1
401 # 设置脚本可执行权限415 # 设置脚本可执行权限
402 execute_process(COMMAND chmod +x ${ES_LOCK_SCRIPT})416 execute_process(COMMAND chmod +x ${ES_LOCK_SCRIPT})
403 message(STATUS "Generated helper script: ${ES_LOCK_SCRIPT}")417 message(STATUS "Generated helper script: ${ES_LOCK_SCRIPT}")
418+ set_property(GLOBAL PROPERTY _ES_LOCK_SCRIPT_GENERATED TRUE)
404 endif ()419 endif ()
405 420 
406 # 1. 解析函数参数421 # 1. 解析函数参数