diff --git a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc index 3bb7f57c56376..bbfee0b1c2729 100644 --- a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc +++ b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc @@ -344,8 +344,19 @@ ProtobufUtil::Status JsonTranscoderConfig::createTranscoder( for (const auto& binding : variable_bindings) { google::grpc::transcoding::RequestWeaver::BindingInfo resolved_binding; - status = type_helper_->ResolveFieldPath(*request_info.message_type, binding.field_path, - &resolved_binding.field_path); + { + /** + * type_helper_ is not a thread safe object. Its used + * `TypeInfoForTypeResolver + * `_ + * uses three mutable maps to cache used data. This function is called in the worker thread. + * Multiple worker threads may use type_helper concurrently and these maps could be corrupted. + * Hence use a mutex to protect it. + */ + absl::MutexLock lock(&type_helper_mutex_); + status = type_helper_->ResolveFieldPath(*request_info.message_type, binding.field_path, + &resolved_binding.field_path); + } if (!status.ok()) { if (ignore_unknown_query_parameters_) { continue; diff --git a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.h b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.h index 95d71aeaada9a..15e07db7a2cac 100644 --- a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.h +++ b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.h @@ -12,6 +12,7 @@ #include "source/common/protobuf/protobuf.h" #include "source/extensions/filters/http/grpc_json_transcoder/transcoder_input_stream_impl.h" +#include "absl/synchronization/mutex.h" #include "google/api/http.pb.h" #include "grpc_transcoding/path_matcher.h" #include "grpc_transcoding/request_message_translator.h" @@ -126,6 +127,7 @@ class JsonTranscoderConfig : public Logger::Loggable, Protobuf::DescriptorPool descriptor_pool_; google::grpc::transcoding::PathMatcherPtr path_matcher_; + mutable absl::Mutex type_helper_mutex_; std::unique_ptr type_helper_; Protobuf::util::JsonPrintOptions print_options_;