diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-13 03:07:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-13 03:07:19 +0300 |
commit | 4df596fc09ef7838d439673f5740993e294c4cd6 (patch) | |
tree | 8431c7d25cd0dfc701905f3d445c273c98d824ed /lib/gitlab/gitaly_client.rb | |
parent | 46c0957d59e2b88b97e6545cb470718869068b13 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/gitaly_client.rb')
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 20eff74c4b1..199257f767d 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -37,9 +37,8 @@ module Gitlab @stubs[storage] ||= {} @stubs[storage][name] ||= begin klass = stub_class(name) - addr = stub_address(storage) - creds = stub_creds(storage) - klass.new(addr, creds, interceptors: interceptors, channel_args: channel_args) + channel = create_channel(storage) + klass.new(channel.target, nil, interceptors: interceptors, channel_override: channel) end end end @@ -99,9 +98,20 @@ module Gitlab address(storage).sub(%r{^tcp://|^tls://}, '') end + # Cache gRPC servers by storage. All the client stubs in the same process can share the underlying connection to the + # same host thanks to HTTP2 framing protocol that gRPC is built on top. This method is not thread-safe. It is + # intended to be a part of `stub`, method behind a mutex protection. + def self.create_channel(storage) + @channels ||= {} + @channels[storage] ||= GRPC::ClientStub.setup_channel( + nil, stub_address(storage), stub_creds(storage), channel_args + ) + end + def self.clear_stubs! MUTEX.synchronize do @stubs = nil + @channels = nil end end |