Repository navigation
fix(wx4): use per-thread ZstdDecompressor, fixes 0xC0000005 crash in batch export - #24
Merged
Merged
Conversation
python-zstandard documents that ZstdDecompressor instances are not thread safe, but the module-level singleton is shared by the 2-4 worker threads of the batch export, which crashed with 0xC0000005 inside backend_c. Create one decompressor per thread instead.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
批量导出(
core/service.py::_run_export_batch(),2-4 个 worker 线程)在全量/多会话导出时,任务刚建立、进度 0% 就进程崩溃,Windows 事件日志为0xc0000005,出错模块多次指向_internal\zstandard\backend_c.cp311-win_amd64.pyd(偏移 0x569bc / 0x5b222)。单会话导出、朋友圈导出正常,纯 Markdown 输出同样崩。原因
wx4/reader.py在模块级创建了一个全局解压器:to_text()直接复用它解压消息内容。而 python-zstandard 官方文档明确写明:ZstdDecompressor 实例不是线程安全的(内部持有一个ZSTD_DCtx)。批量导出由多个 worker 线程同时调用to_text(),共享同一个实例即造成原生层内存破坏并崩溃。修复
改为 thread-local:每个线程各持有一个
ZstdDecompressor,线程内复用(不牺牲解压性能),线程间不再共享同一ZSTD_DCtx。zstd 缺失时行为保持不变(仍返回空字符串)。验证
本 PR 只改
wx4/reader.py一个文件(+18/-4),不改任何调用方签名与导出逻辑。关联 issue: #22