consul
consul copied to clipboard
Move sidecar port assignment logic to locked stage of add flow
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
PR Checklist
- [ ] updated test coverage
- [N/A] external facing docs updated
- [N/A] not a security concern