Lock the sender map read in ProducerClient::GetSender
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::GetSender reads the sender map with no lock. EnsureSender changes the same map under m_sendersLock. Two threads that send to different partitions for the first time cause a data race. One thread reads a std::map while the other thread writes it. This is undefined behavior. Send and CreateBatch both use this path.
Parent: #7284. Severity tags follow the key in #7252. The code anchors refer to commit 2de7c583e.
Motivation
GetSender has three lines and takes no lock (src/producer_client.cpp:259-263):
Azure::Core::Amqp::_internal::MessageSender ProducerClient::GetSender(
std::string const& partitionId)
{
return m_senders.at(partitionId);
}
EnsureSender writes to the same map under m_sendersLock (src/producer_client.cpp:229-257). A write can rebalance the red-black tree that holds a std::map. A parallel at() call then reads that tree while it moves.
ProducerClient::Send calls GetSender in its retry lambda (src/producer_client.cpp:111). CreateBatch calls it at src/producer_client.cpp:90. Both callers call EnsureSender first, so one thread alone is safe. Two threads with different partitions are not safe. Thread A can write the sender for partition 1 while thread B reads the sender for partition 0.
GetSession takes m_sessionsLock for the same pattern. The missing lock in GetSender therefore looks like an error.
Proposal
- Take
m_sendersLockinProducerClient::GetSenderbefore it readsm_senders(src/producer_client.cpp:259-263). [GA blocker] - Examine
ConsumerClientfor the same pattern onm_receiversandm_receiversLock(inc/azure/messaging/eventhubs/consumer_client.hpp:206). [GA blocker]
This is the smallest correct change. It keeps all the signatures. The method releases the lock before the caller uses the MessageSender handle. The method returns the handle by value, so no reference stays alive after the lock. #7288 replaces this mutex with a std::shared_mutex later. Do this change first, because it is small and it stops the undefined behavior now.
Validation
- The thread sanitizer reports no race. Use N threads. Each thread sends to a different partition that no thread used before.
- The same test causes a thread sanitizer error before the change.
- The Event Hubs unit tests pass.
- Lingua principale
- C++
- Stelle
- 207
- Fork
- 173
- Merge medio
- 1g 10h
- PR unite (30g)
- 30
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
-
DataLakeFileSystemClient::ListPaths() throws JSON exception due to accessing undefined fieldsApertacustomer-reported needs-triage question
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Azure/azure-sdk-for-cpp#7435 ·
I maintainer di solito rispondono entro 1 giorno
-
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
-
DataLakeDirectoryClient::ListPaths() throws exception due to incorrect format used for date-time fieldsForse già presa @seanmcc-msft l’ha presa oggi. Apertacustomer-reported needs-triage question
Azure/azure-sdk-for-cpp#7436 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Azure/azure-sdk-for-cpp
Issue simili
-
Broken links in the docsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
microsoft/onnxruntime#33018 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
ChromieCraft Generic Confirmed World Event
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
azerothcore/azerothcore-wotlk#27882 ·
I maintainer di solito rispondono entro 1 giorno
-
MacOS build failureApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
aristocratos/btop#1874 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
cataclysmbn/Cataclysm-BN#10447 ·
I maintainer di solito rispondono entro 1 giorno