UnixNetProcessor::connect_re allocates from another thread's freelist

未关闭
#14,196 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp

调研方向

Start with the cited allocation and affinity paths in src/iocore/net/UnixNetProcessor.cc, then read the ownership rule in include/iocore/eventsystem/Thread.h and the cache operations in include/iocore/eventsystem/ProxyAllocator.h. Trace how THREAD_ALLOC_INIT behaves when the selected thread differs from the calling thread, including the TSNetConnect example in src/api/InkAPI.cc. Done means preventing access to another thread’s ProxyAllocator cache and handling the reported missing mutex check safely.

由索引模型根据 Issue 内容生成。

描述

Bug Network Threads TS API

UnixNetProcessor::connect_re chooses the thread the new connection will run on with eventProcessor.assign_affinity_by_type(cont, opt.etype) (UnixNetProcessor.cc#L192-L193). It then allocates the NetVC from that thread's per-thread freelist, THREAD_ALLOC_INIT(netVCAllocator, t) (UnixNetProcessor.cc#L316).

assign_affinity_by_type returns the calling thread only if it already has the requested event type. Otherwise it returns the continuation's affinity thread or a newly assigned thread of that type (UnixEventProcessor.cc#L662-L677). The allocators have two layers, and only one of them is safe to share between threads. The global ClassAllocator freelists are lock-free and safe to use from any thread (ink_queue.cc#L206). In front of each global allocator, every Thread keeps a ProxyAllocator cache. That cache is a plain singly linked list, popped by thread_alloc and pushed by THREAD_FREE with no atomics or lock (ProxyAllocator.h#L54-L60, #L106-L119). It avoids the CAS on the hot path, and that is only safe because a single thread owns it. Thread.h states the rule: the Thread passed to the macros MUST be the calling OS thread's own Thread (Thread.h#L175-L177). THREAD_ALLOC_INIT only reaches the lock-free global list when that cache is empty. So a connect started from a thread that isn't ET_NET pops another thread's ProxyAllocator cache while that thread may be pushing to or popping from it. One example is a plugin calling TSNetConnect from an ET_TASK continuation (InkAPI.cc#L6774). This is a data race that can corrupt that cache, for example handing the same NetVC out twice.

assign_affinity_by_type also dereferences cont->mutex->thread_holding without a check (L664). It crashes if the caller doesn't hold the continuation's mutex.

A fix is to allocate from the current thread, or from the global allocator, when t != this_ethread().


generated with Claude Opus 5.5 by Josiah VanderZee

主要语言
C++
星标
2k
派生
903
平均合并
4 天 4 小时
30 天内合并 PR
135

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/trafficserver 的其他 Issue

查看 apache/trafficserver 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。