Repository navigation
fix(hooks): 修复插件进程退出后 HookList 残留死插件、每封邮件报错的问题 - #359
Merged
Jinnrry merged 1 commit intoAug 30, 2026
Merged
Conversation
问题: 插件进程崩溃或退出后,清理协程会执行 delete(HookList, info.Name()), 但注册时使用的键是 hk.GetName() 的返回值(如 SpamBlock), 而 info.Name() 是插件文件名(如 spam_block),两者不一致, 导致已死插件的 HookSender 永远无法从 HookList 中移除。 之后每封邮件发送/接收都会尝试连接已死的 unix socket, 产生大量 "connection refused" 错误,且垃圾过滤功能静默失效。 修复: 1. 记录每个插件注册时实际使用的键(registeredName), 清理协程用同一个键执行 RemoveHook。 2. 为 HookList 增加 sync.RWMutex 保护(插件退出是并发写, 收发邮件是并发读,不加锁修好 key 后会引入数据竞争)。 3. 所有读取点改用 AllHooks()/HookNames()/GetHook() 线程安全访问器。 4. GetName 失败时退回插件文件名作为键,避免空键。 5. 新增单元测试覆盖键一致性、快照不可变性和并发安全(含 -race)。
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.
问题:
插件进程崩溃或退出后,清理协程会执行 delete(HookList, info.Name()),
但注册时使用的键是 hk.GetName() 的返回值(如 SpamBlock),
而 info.Name() 是插件文件名(如 spam_block),两者不一致,
导致已死插件的 HookSender 永远无法从 HookList 中移除。
之后每封邮件发送/接收都会尝试连接已死的 unix socket,
产生大量 "connection refused" 错误,且垃圾过滤功能静默失效。
修复: