From adc79e54c5f65914c668d6d2e7f0ea6f1b4b7cd4 Mon Sep 17 00:00:00 2001 From: yibo Date: Sun, 7 Jun 2026 23:54:45 +0800 Subject: [PATCH] fix(lifelog): BlockProcessor 崩溃自隔离,防毒块死循环崩 app --- lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/service/BlockProcessor.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+), 0 deletions(-) diff --git a/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/service/BlockProcessor.kt b/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/service/BlockProcessor.kt index 573a24a..f29eaca 100644 --- a/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/service/BlockProcessor.kt +++ b/lifelog-recorder/app/src/main/kotlin/com/lemon/lifelog/service/BlockProcessor.kt @@ -34,6 +34,22 @@ class BlockProcessor( private val clusterer: SpeakerClusterer, ) { suspend fun process(dir: File) { + // 崩溃自隔离:处理前写 .attempt 标记;若启动时发现标记还在(= 上次处理它时进程在 + // native 层崩了,没走到删目录),说明这是「毒块」——移到 blocks_quarantine/ 跳过, + // 避免每次重启都崩在同一块上死循环。native SIGSEGV 无法 try/catch,只能这样防御。 + val marker = File(dir, ".attempt") + if (marker.exists()) { + val q = File(dir.parentFile?.parentFile, "blocks_quarantine").apply { mkdirs() } + val dest = File(q, dir.name) + Log.w(TAG, "block ${dir.name} crashed last attempt → quarantine") + withContext(Dispatchers.IO) { + dest.deleteRecursively() + if (!dir.renameTo(dest)) { dir.copyRecursively(dest, overwrite = true); dir.deleteRecursively() } + } + return + } + withContext(Dispatchers.IO) { runCatching { marker.createNewFile() } } + val loaded = withContext(Dispatchers.IO) { BlockBuffer.load(dir) } if (loaded == null || loaded.samples.isEmpty()) { withContext(Dispatchers.IO) { dir.deleteRecursively() } -- libgit2 0.21.4