Skip to content

fix(DailyNoteSearcher): resolve Windows WSAEWOULDBLOCK 10035 and ECONNRESET on HTTP search - #488

Merged
lioensky merged 1 commit into
lioensky:mainfrom
infinite-vector:fix/dailynote-searcher-nonblocking-socket
Oct 6, 2026
Merged

lioensky merged 1 commit into
lioensky:mainfrom
infinite-vector:fix/dailynote-searcher-nonblocking-socket

Conversation

@infinite-vector

Copy link
Copy Markdown
Collaborator

动机与背景 (Motivation)

在 Windows 平台下,当高并发或密集触发 {{...日记本::BM25}} / DirectDiaryTextProcessor 纯文本检索时,终端偶发打印以下异常并导致日记召回劣化回退到 recent window:

  • [DailyNoteSearcher Service] HTTP request failed: 无法立即完成一个非阻止性套接字操作。 (os error 10035)
  • [DirectDiaryTextProcessor] BM25 OR prefilter failed, falling back to recent window: read ECONNRESET

根因分析:

  1. Windows Winsock 非阻塞继承陷阱:在 Windows 系统下,由非阻塞 TcpListener(用于配合循环优雅退出)accept() 出的子 TcpStream 会默认继承非阻塞状态。工作线程执行同步 stream.read() 时,若数据未完全进入内核缓冲区,会抛出 WSAEWOULDBLOCK (10035) 错误。
  2. 级联连接断开:handle_http_connection 遭遇 10035 后函数退出导致连接被服务端 Drop,而此时 Node.js 客户端正等待响应或发送剩余分包,撞上服务端 RST 报文引发 read ECONNRESET。

解决方案 (Solution)

  1. 服务端(Rust):
    • 在 Plugin/DailyNoteSearcher/src/src/main.rs:handle_http_connection 顶部,显式对子连接调用 stream.set_nonblocking(false) 恢复阻塞语义,抹平 Windows 平台差异。
    • 注入 60s 读写超时(set_read_timeout / set_write_timeout),并在响应完毕后调用 stream.flush() 确保报文完整送达。
    • 重新编译并同步更新了 Windows x86_64 Release 二进制产物。
  2. 客户端(Node.js):
    • 在 Plugin/RAGDiaryPlugin/DirectDiaryTextProcessor.js 的 postDailyNoteSearcherHttp 与 Plugin/DailyNoteSearcher/DailyNoteSearcher.js 的 postJson 中增加瞬时网络错误识别(ECONNRESET / 10035 / socket hang up / EPIPE)。
    • 植入 3 次指数退避重试(带微秒抖动),确保在极端突发流量下具备弹性抗抖动能力。

测试与验证 (Verification)

  • 并发压测:使用并发脚本模拟 30 路并发 HTTP POST 搜索请求,30/30 全部成功返回,响应均在 10ms~30ms 级别,未再出现任何 10035 错误与 ECONNRESET。
  • 功能回归:全量测试单次关键字匹配、正则匹配、多词元 OR 预过滤与零结果空回,格式与数据完整一致。

@lioensky
lioensky merged commit 4bb6424 into lioensky:main Oct 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants