Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Move the Event Hubs link and session creation outside the client locks

Aperta
#7,286 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

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

Event Hubs

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 EnsureSender to a double-checked write (src/producer_client.cpp:225-257). [GA blocker]
  • Change EnsureSession and EnsureConnection in the same way (src/producer_client.cpp:197-224). [GA blocker]
  • Change the equivalent ConsumerClient methods in the same way (src/consumer_client.cpp:120-165). [GA blocker]
  • Change m_sessionsLock from std::recursive_mutex to std::mutex after 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_sessionsLock is a plain std::mutex. The tests pass.
Lingua principale
C++
Stelle
206
Fork
177
Merge medio
2g 6h
PR unite (30g)
35

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/azure-sdk-for-cpp

Tutte le issue di Azure/azure-sdk-for-cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.