UnixNetProcessor::connect_re allocates from another thread's freelist

オープン
#14,196 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
135

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/trafficserver のほかの issue

apache/trafficserver の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。