Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/api_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void MetadataApiServer::Handler::operator()(const HttpServer::request& request,
<< " body: " << request.body;
if (request.method == "GET" && request.destination.find(kPrefix) == 0) {
std::string id = request.destination.substr(kPrefix.size());
std::lock_guard<std::mutex> lock(agent_.mu_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious -- are there more than 1 read threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the number of server threads is specified in the config (MetadataApiNumThreads). But it's enough to have 1 read thread and 1 write thread to trigger the race condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. I only ask because read threads should not have to block other read threads. Its only when writes happen or attempts to read when a write is in progress that the mutex actually comes in. Probably a micro-optimization to be deferred for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very true. Will fix this later (I'm not too happy with the direct access to the agent's fields, including the mutex, from a friend class anyway).

const auto result = agent_.resource_map_.find(id);
if (result == agent_.resource_map_.end()) {
// TODO: This could be considered log spam.
Expand Down