Commit ac055bbe authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'fix_infinite_loop_lb_primary_only' into 'master'

Skip retrying for reads on connection errors if primary only

See merge request gitlab-org/gitlab!73715
parents 626d775d 7d0c81a7
......@@ -54,7 +54,10 @@ module Gitlab
connection = host.connection
return yield connection
rescue StandardError => error
if serialization_failure?(error)
if primary_only?
# If we only have primary configured, retrying is pointless
raise error
elsif serialization_failure?(error)
# This error can occur when a query conflicts. See
# https://www.postgresql.org/docs/current/static/hot-standby.html#HOT-STANDBY-CONFLICT
# for more information.
......
......@@ -141,6 +141,24 @@ RSpec.describe Gitlab::Database::LoadBalancing::LoadBalancer, :request_store do
lb.read { raise conflict_error }
end
context 'only primary is configured' do
let(:lb) do
config = Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base)
allow(config).to receive(:load_balancing_enabled?).and_return(false)
described_class.new(config)
end
it 'does not retry a query on connection error if only the primary is configured' do
host = double(:host, query_cache_enabled: true)
allow(lb).to receive(:host).and_return(host)
allow(host).to receive(:connection).and_raise(PG::UnableToSend)
expect { lb.read }.to raise_error(PG::UnableToSend)
end
end
it 'uses the primary if no secondaries are available' do
allow(lb).to receive(:connection_error?).and_return(true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment