consul icon indicating copy to clipboard operation
consul copied to clipboard

Backport of Move sidecar port assignment logic to locked stage of add flow into release/1.13.x

Open hc-github-team-consul-core opened this issue 3 years ago • 1 comments

Backport

This PR is auto-generated from #14057 to be assessed for backporting due to the inclusion of the label backport/1.13.

WARNING automatic cherry-pick of commits failed. Commits will require human attention.

merge conflict error: POST https://api.github.com/repos/hashicorp/consul/merges: 409 Merge conflict []

The below text is copied from the body of the original PR.


Closes #8254

Description

This relocates automatic sidecar port assignment logic to a locked method immediately before registration, thereby preventing collisions when handling simultaneous requests.

Testing & Reproduction steps

Manual verification:

  • Submit many simultaneous requests for registration with sidecar proxy and no port specified: for name in $(shuf -i 1-10000); do curl -d '{"name": "'$name'", "connect": {"sidecar_service": {}}}' -X PUT localhost:8500/v1/agent/service/register &; echo registered $name; done
  • See how many duplicate ports have been registered: curl localhost:8500/v1/agent/services | jq -r ' . | to_entries | map(select(.key | match("sidecar";"i"))) | map(.value) | .[] | .Port' | sort | uniq -d
  • Before this change: there should be several duplicate ports
  • After this change: no duplicate ports

Links

GH Issue Pre-req PR 1 Pre-req PR 2

PR Checklist

  • [ ] updated test coverage
  • [N/A] external facing docs updated
  • [N/A] not a security concern

Overview of commits
  • 3a8999a98dd812c8eeb0591fbb8b98e143d70931

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Sep 07 '22 00:09 hashicorp-cla