Move the Event Hubs link and session creation outside the client locks
I maintainer di solito rispondono entro 1 giorno
@j7nw4r ci sta già lavorando.
Dal 5/8/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 206
- Fork
- 177
- Merge medio
- 2g 6h
- PR unite (30g)
- 35
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Azure/azure-sdk-for-cpp
-
bug EngSys
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Azure/azure-sdk-for-cpp#7362 ·
I maintainer di solito rispondono entro 1 giorno
-
Client needs-team-attention Service Attention Storage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/azure-sdk-for-cpp#7347 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Client Event Hubs needs-team-attention Service Attention
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Azure/azure-sdk-for-cpp#7333 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Azure Storage STG105 Feature TestsForse già presa @Jinming-Hu l’ha presa 19 giorni fa. ApertaClient Storage
Azure/azure-sdk-for-cpp#7449 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Azure.Core bug test-enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
Azure/azure-sdk-for-cpp#7401 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Azure/azure-sdk-for-cpp
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
k2-fsa/sherpa-onnx#4100 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Mod: Part Design Topic: User Interface
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
A-tools P-medium S-ready-to-start task
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
sistemicorp/scripts#62 ·