Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retry for UniqueConstraintViolation in RouteCreate (v3) #3697

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions app/actions/route_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def create(message:, space:, domain:, manifest_triggered: false)
rescue Sequel::ValidationFailed => e
validation_error!(e, route.host, route.path, route.port, space, domain)
rescue Sequel::UniqueConstraintViolation => e
logger.warn("error creating route #{e}, retrying once")
RouteCreate.new(user_audit_info).create(message:, space:, domain:, manifest_triggered:)
logger.warn("error creating route #{e}, retrying")
RouteCreate.new(@user_audit_info).create(message:, space:, domain:, manifest_triggered:)
end

private
Expand Down
40 changes: 40 additions & 0 deletions spec/integration/parallel_route_creation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'spec_helper'

module VCAP::CloudController
RSpec.describe RouteCreate do
describe 'parallel creation of internal routes' do
it 'retries until find_next_vip_offset does not return a conflicting number' do
# Don't create events
allow_any_instance_of(Repositories::RouteEventRepository).to receive(:record_route_create)

threads = []
10.times do
threads << Thread.new do
user_audit_info = UserAuditInfo.new(user_email: Sham.email, user_guid: Sham.guid)
message = RouteCreateMessage.new(host: Sham.host)
space = Space.make
domain = SharedDomain.make(internal: true)

route = nil
expect do
route = RouteCreate.new(user_audit_info).create(message:, space:, domain:)
end.not_to raise_error
expect(route).to exist

# Wait until all routes are created...
sleep(1)
delete_db_entries(route, domain, space)
end
end
threads.each(&:join)
end
end

def delete_db_entries(route, domain, space)
organization = space.organization
quota_definition = organization.quota_definition

[route, domain, space, organization, quota_definition].each(&:delete)
end
end
end