[oauth] Fix TSAN race in oauth2 authentication (#32516)

Internal bug ref: b/271334230
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/32527/head
Craig Tiller 2 years ago committed by GitHub
parent c4a0b2736a
commit 1f89639eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  2. 2
      src/core/lib/security/credentials/oauth2/oauth2_credentials.h

@ -267,10 +267,7 @@ void grpc_oauth2_token_fetcher_credentials::on_http_response(
// Invoke callbacks for all pending requests.
while (pending_request != nullptr) {
if (status == GRPC_CREDENTIALS_OK) {
pending_request->md->Append(
GRPC_AUTHORIZATION_METADATA_KEY, access_token_value->Ref(),
[](absl::string_view, const grpc_core::Slice&) { abort(); });
pending_request->result = std::move(pending_request->md);
pending_request->result = access_token_value->Ref();
} else {
auto err = GRPC_ERROR_CREATE_REFERENCING(
"Error occurred when fetching oauth2 token.", &error, 1);
@ -338,7 +335,15 @@ grpc_oauth2_token_fetcher_credentials::GetRequestMetadata(
if (!pending_request->done.load(std::memory_order_acquire)) {
return grpc_core::Pending{};
}
return std::move(pending_request->result);
if (pending_request->result.ok()) {
pending_request->md->Append(
GRPC_AUTHORIZATION_METADATA_KEY,
std::move(*pending_request->result),
[](absl::string_view, const grpc_core::Slice&) { abort(); });
return std::move(pending_request->md);
} else {
return pending_request->result.status();
}
};
}

@ -102,7 +102,7 @@ struct grpc_oauth2_pending_get_request_metadata
grpc_polling_entity* pollent;
grpc_core::ClientMetadataHandle md;
struct grpc_oauth2_pending_get_request_metadata* next;
absl::StatusOr<grpc_core::ClientMetadataHandle> result;
absl::StatusOr<grpc_core::Slice> result;
};
// -- Oauth2 Token Fetcher credentials --

Loading…
Cancel
Save