From 281bc510e37a0806878c146d2ff5b801ba67dfd2 Mon Sep 17 00:00:00 2001 From: Dang Dat Date: Thu, 5 Nov 2026 13:32:16 +0700 Subject: [PATCH] ci: stop a hung Android memory check on silence and keep logcat The first Android run hung for 39 min between two tests and was only cancelled by the 60 min job limit. Kill patrol after 4 min without output once the tests start (10 min during the Gradle build), print Flutter logs and save logcat on failure. Android job limit is 35 min. --- .github/workflows/memory-leak-check.yaml | 2 +- scripts/memory-leak-check.sh | 33 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/memory-leak-check.yaml b/.github/workflows/memory-leak-check.yaml index 1b5ff2e0f..039393972 100644 --- a/.github/workflows/memory-leak-check.yaml +++ b/.github/workflows/memory-leak-check.yaml @@ -85,7 +85,7 @@ jobs: android: name: Memory leak check (android) runs-on: ubuntu-24.04 - timeout-minutes: 60 + timeout-minutes: 35 steps: - name: Checkout repository uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 diff --git a/scripts/memory-leak-check.sh b/scripts/memory-leak-check.sh index 679e26302..1f49b28ee 100644 --- a/scripts/memory-leak-check.sh +++ b/scripts/memory-leak-check.sh @@ -100,11 +100,40 @@ if [ "$PLATFORM" = web ]; then ${EXTRA_PATROL_ARGS[@]+"${EXTRA_PATROL_ARGS[@]}"} "${DART_DEFINES[@]}" else export ANDROID_TEST_BUILD_TYPE=profile - patrol test -v --profile --tags=memory --device=emulator-5554 \ - ${EXTRA_PATROL_ARGS[@]+"${EXTRA_PATROL_ARGS[@]}"} "${DART_DEFINES[@]}" + # A hung instrumentation prints nothing, so kill patrol on silence, not on a fixed budget. + # The Gradle build is silent for up to ~6 min; test steps print every few seconds. + BUILD_IDLE_LIMIT=600 + TEST_IDLE_LIMIT=240 + PID_FILE="$CI_LOGS/patrol.pid" + bash -c 'echo $$ > "$1"; shift; exec "$@"' _ "$PID_FILE" \ + patrol test -v --profile --show-flutter-logs --tags=memory --device=emulator-5554 \ + ${EXTRA_PATROL_ARGS[@]+"${EXTRA_PATROL_ARGS[@]}"} "${DART_DEFINES[@]}" 2>&1 | + { + limit=$BUILD_IDLE_LIMIT + while true; do + if IFS= read -r -t "$limit" line; then + printf '%s\n' "$line" + case "$line" in *"Starting "*" tests on"*) limit=$TEST_IDLE_LIMIT ;; esac + elif [ $? -gt 128 ]; then + echo "No patrol output for ${limit}s: killing the hung run" + patrol_pid=$(cat "$PID_FILE" 2>/dev/null) + if [ -n "$patrol_pid" ]; then + pkill -TERM -P "$patrol_pid" 2>/dev/null + kill -TERM "$patrol_pid" 2>/dev/null + fi + exit 124 + else + break + fi + done + } fi PATROL_EXIT=$? +if [ "$PLATFORM" = android ] && [ "$PATROL_EXIT" -ne 0 ]; then + adb -s emulator-5554 logcat -d -t 20000 > "$CI_LOGS/logcat.txt" 2>&1 || true +fi + python3 -I scripts/memory-leak-report.py "$MEMORY_DIR" integration_test/memory/memory_rules.json REPORT_EXIT=$?