Move the Event Hubs link and session creation outside the client locks
メンテナーはふだん 1 日以内に返信
@j7nw4r がすでに取り組んでいます。
2026年8月5日 から。
評価
この issue はまだ評価されていません。
説明
Summary
ProducerClient::EnsureSender keeps m_sendersLock across the link creation and MessageSender::Open. Open sends data to the service and waits for the answer. The first send to one partition must therefore wait for the link setup of every other partition. This also puts a lock across a call that the AMQP layer identifies as a deadlock risk.
Parent: #7284. Severity tags follow the key in #7252. The code anchors refer to commit 2de7c583e.
Motivation
EnsureSender takes the lock at src/producer_client.cpp:229. It keeps the lock through GetSession(partitionId).CreateMessageSender(targetUrl, senderOptions) and sender.Open(context). It writes to the map at src/producer_client.cpp:256. Open does the AMQP attach handshake, so the lock stays locked for a full network round trip.
EnsureSession and EnsureConnection have the same design under m_sessionsLock. That mutex is a std::recursive_mutex (inc/azure/messaging/eventhubs/producer_client.hpp:197). The recursion is necessary only because EnsureSession calls EnsureConnection while it keeps the lock. Move the creation outside the lock, and the recursion stops. The mutex can then be a plain mutex.
The AMQP layer identifies a related risk. MessageSenderImpl::Open registers the link with the global polling thread through AddPollable (azure-core-amqp/src/impl/uamqp/amqp/message_sender.cpp:290,340). The note at azure-core-amqp/src/common/global_state.cpp:159 says that the caller must not keep a connection lock or a link lock when it calls AddPollable. The polling thread takes the connection lock, and the two threads then deadlock.
m_sendersLock is an Event Hubs lock, not a link lock. The deadlock in that note therefore does not occur as written. The call stack does nest Event Hubs locks across that boundary. The transport authors identified this pattern as a risk.
Proposal
- Change
EnsureSenderto a double-checked write (src/producer_client.cpp:225-257). [GA blocker] - Change
EnsureSessionandEnsureConnectionin the same way (src/producer_client.cpp:197-224). [GA blocker] - Change the equivalent
ConsumerClientmethods in the same way (src/consumer_client.cpp:120-165). [GA blocker] - Change
m_sessionsLockfromstd::recursive_mutextostd::mutexafter the recursion stops (inc/azure/messaging/eventhubs/producer_client.hpp:197,inc/azure/messaging/eventhubs/consumer_client.hpp:210). [GA quality bar]
The double-checked write has four steps. Read the map under the lock. Release the lock. Build the link and call Open with no lock. Take the lock again and write to the map after a second read.
Two threads can create a link for the same partition at the same time. One thread wins. The other thread must close its extra link before it returns the handle of the winner. Do not discard the extra link, because that leaks a link.
Validation
- No lock stays locked across
Open,CreateMessageSender, or any other call that uses the network. A code review of the four call sites shows this. - A test that opens links for N partitions at the same time takes about the time of one link setup.
- The thread sanitizer reports no race for the double-checked write.
- Two threads that create the same partition at the same time leak no link.
-
m_sessionsLockis a plainstd::mutex. The tests pass.
- 主要言語
- C++
- スター
- 206
- フォーク
- 178
- 平均マージ
- 2日 15時間
- マージ済み PR(30日)
- 33
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Azure/azure-sdk-for-cpp のほかの issue
-
bug EngSys
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
Azure/azure-sdk-for-cpp#7362 ·
メンテナーはふだん 1 日以内に返信
-
Client needs-team-attention Service Attention Storage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Azure/azure-sdk-for-cpp#7347 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Client Event Hubs needs-team-attention Service Attention
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
Azure/azure-sdk-for-cpp#7333 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Azure Storage STG105 Feature Tests再び着手できるかも @Jinming-Hu が 30 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンClient Storage
Azure/azure-sdk-for-cpp#7449 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Azure.Core bug test-enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
Azure/azure-sdk-for-cpp#7401 ·
メンテナーはふだん 1 日以内に返信
Azure/azure-sdk-for-cpp の issue をすべて見る
似ている issue
-
Linux npm packaging leaves workspace files that block subsequent CI checkout対応中かも @Spockkk0225 が今日担当しました。 オープンci
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
alibaba/neug#1195 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
SCIInstitute/SCIRun#2909 ·
メンテナーはふだん 2 日以内に返信
-
area: packaging blocked dependencies P3: low post-stable value: medium
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
patrick-hudson/put.gd-desktop#1210 ·
メンテナーはふだん 1 日以内に返信