Skip to content

fix: deep copy status in translator layer to avoid race#8778

Merged
zirain merged 1 commit into
envoyproxy:mainfrom
rudrakhp:translator_coalesce_race
Apr 19, 2026
Merged

fix: deep copy status in translator layer to avoid race#8778
zirain merged 1 commit into
envoyproxy:mainfrom
rudrakhp:translator_coalesce_race

Conversation

@rudrakhp

Copy link
Copy Markdown
Member

What type of PR is this?

fix: deep copy status in translator layer to avoid race

What this PR does / why we need it:
DeepCopy() calls were removed in #6940 but are required to avoid race between deepEqual() in watchable coalesce routine and status updates in gateway api translator routine. Replaced plain shallow copy with deep copy only status.

Also includes a minor spelling fix SeverOptions -> ServerOptions

Which issue(s) this PR fixes:

Fixes #8771

Release Notes: Yes

@rudrakhp rudrakhp requested a review from a team as a code owner April 17, 2026 09:17
@netlify

netlify Bot commented Apr 17, 2026

Copy link
Copy Markdown

Deploy Preview for cerulean-figolla-1f9435 canceled.

Name Link
🔨 Latest commit e8199ae
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/69e4dc614602da00085166eb

@rudrakhp rudrakhp force-pushed the translator_coalesce_race branch from cc8f6c8 to 99a5c61 Compare April 17, 2026 09:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc8f6c8c98

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/gatewayapi/envoypatchpolicy.go Outdated

for _, policy := range envoyPatchPolicies {
for i, orig := range envoyPatchPolicies {
envoyPatchPolicies[i] = deepCopyEnvoyPatchPolicyStatus(orig)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid mutating shared EnvoyPatchPolicies slice in place

Writing the deep-copied pointer back into envoyPatchPolicies[i] still mutates the snapshot object passed from GatewayAPIResources. If a new provider update arrives while translation is running, watchable’s equality/coalescing path can read that same slice concurrently, so this assignment can still trigger the control-plane race the patch is trying to eliminate. Keep the copy in a local variable and do not modify the input slice.

Useful? React with 👍 / 👎.

policy := &policy
// Clone the Object map to avoid racing with the watchable coalesce goroutine.
policy.Object = maps.Clone(policy.Object)
policies[policyIndex] = policy

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop writing cloned extension policies into input slice

policies[policyIndex] = policy mutates the shared resources.ExtensionServerPolicies snapshot before translation completes. During concurrent updates, watchable can deep-compare that same slice in another goroutine, so this write can race even after cloning policy.Object. Build status/IR from a local copied policy and leave the incoming slice unchanged.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Apr 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.74214% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.39%. Comparing base (d80fb5b) to head (e8199ae).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/gatewayapi/extensionserverpolicy.go 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8778      +/-   ##
==========================================
+ Coverage   74.35%   74.39%   +0.04%     
==========================================
  Files         245      245              
  Lines       38847    38951     +104     
==========================================
+ Hits        28883    28978      +95     
- Misses       7963     7969       +6     
- Partials     2001     2004       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread internal/gatewayapi/backend.go Outdated
// Status is mutated during translation and shares a pointer with the watchable coalesce goroutine.
func deepCopyBackendStatus(in *egv1a1.Backend) *egv1a1.Backend {
out := *in
in.Status.DeepCopyInto(&out.Status)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use backend.DeepCopy directly? which is better for understanding.

@rudrakhp rudrakhp Apr 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is less efficient than this as we only need deep copy for status which is modified. Rest of the policy can be a shallow copy. We were already doing complete deep copy before #6940 tried to optimize it.

@rudrakhp rudrakhp force-pushed the translator_coalesce_race branch 2 times, most recently from c64694a to dc37ca3 Compare April 17, 2026 10:39
@rudrakhp rudrakhp requested review from a team and zirain April 17, 2026 11:14
@rudrakhp rudrakhp force-pushed the translator_coalesce_race branch from b0b74a1 to dbc7ecb Compare April 18, 2026 06:35
@jukie

jukie commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

/retest

Comment thread internal/gatewayapi/securitypolicy.go Outdated
policy, found := handledPolicies[policyName]
if !found {
policy = currPolicy
policy = deepCopySecurityPolicyStatus(currPolicy)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cant we just do it once in L142 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, creating copies once in XCopiesWithStatusDeepCopy() before reusing them.

@rudrakhp rudrakhp force-pushed the translator_coalesce_race branch from 52c3850 to 923e3b6 Compare April 19, 2026 07:41
@rudrakhp rudrakhp force-pushed the translator_coalesce_race branch from 923e3b6 to e8199ae Compare April 19, 2026 13:45
@rudrakhp rudrakhp requested a review from arkodg April 19, 2026 13:56

@arkodg arkodg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@zirain zirain merged commit 3f70a89 into envoyproxy:main Apr 19, 2026
80 of 85 checks passed
rudrakhp added a commit that referenced this pull request Apr 24, 2026
* fix json report (#8614)

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>

* fix: deep copy status in translator layer to avoid race (#8778)

Signed-off-by: Rudrakh Panigrahi <[email protected]>

* chore: setup translator test (#7627)

* chore: setup gatewayapi translator test

Signed-off-by: kkk777-7 <[email protected]>

* remove: duplicate resources in testfiles

Signed-off-by: kkk777-7 <[email protected]>

* update gatewayapi test output

Signed-off-by: kkk777-7 <[email protected]>

---------

Signed-off-by: kkk777-7 <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>

* perf: introduce translator context (#7535)

* perf: introduce translator context

Signed-off-by: kkk777-7 <[email protected]>

* perf: add policy map in translator context

Signed-off-by: kkk777-7 <[email protected]>

* chore: update tranlate bench

Signed-off-by: kkk777-7 <[email protected]>

* Revert "perf: add policy map in translator context"

This reverts commit 14a3784.

Signed-off-by: kkk777-7 <[email protected]>

* add translator context method, remove unused function

Signed-off-by: kkk777-7 <[email protected]>

* update gatewayapi test output

Signed-off-by: kkk777-7 <[email protected]>

* add resources in translator context

Signed-off-by: kkk777-7 <[email protected]>

* add gatewayapi translate bench

Signed-off-by: kkk777-7 <[email protected]>

* fix: set resources in translator context

Signed-off-by: kkk777-7 <[email protected]>

* fix: go lint

Signed-off-by: kkk777-7 <[email protected]>

* address comments

Signed-off-by: kkk777-7 <[email protected]>

* feat: support egctl translate options

Signed-off-by: kkk777-7 <[email protected]>

* update: bench test

Signed-off-by: kkk777-7 <[email protected]>

* update embedded field

Signed-off-by: kkk777-7 <[email protected]>

* fix gatewayapi testdata output

Signed-off-by: kkk777-7 <[email protected]>

---------

Signed-off-by: kkk777-7 <[email protected]>
Co-authored-by: zirain <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>

* fix gen-check

Signed-off-by: Rudrakh Panigrahi <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: kkk777-7 <[email protected]>
Co-authored-by: Huabing (Robin) Zhao <[email protected]>
Co-authored-by: Kota Kimura <[email protected]>
Co-authored-by: zirain <[email protected]>
skos-ninja pushed a commit to skos-ninja/envoy-gateway that referenced this pull request May 1, 2026
cnvergence added a commit that referenced this pull request May 9, 2026
* fix json report (#8614)

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
(cherry picked from commit 4768ca7)

* fix: deep copy status in translator layer to avoid race (#8778)

Signed-off-by: Rudrakh Panigrahi <[email protected]>
(cherry picked from commit 3f70a89)

* fix: force HTTP1 for upstream connections for WS and WSS backends (#8699)

* force HTTP1 for upstream connections for WS and WSS backends

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* use different clusters for mixed upstream protocols

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* update

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

* fix lint

Signed-off-by: Huabing (Robin) Zhao <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
(cherry picked from commit 7633125)

* fix: reason with multiple errors rejected validation (#8859)

* fix: reason with multiple errors rejected validation

Signed-off-by: zirain <[email protected]>

* release notes

Signed-off-by: zirain <[email protected]>

* fix lint

Signed-off-by: zirain <[email protected]>

---------

Signed-off-by: zirain <[email protected]>
(cherry picked from commit 7811d86)

* feat(chart): Allow configuring envoy proxy image via helm chart (#8785)

* feat: Allow configuring envoy proxy defaults via helm chart

This commit is a continuation of the previous work to support supplying default proxy settings added in #7698 and adds three new chart values under `global.images.envoyProxy`:

| Value | Type | Default | Description |
|----------------------------------------|--------|------|---------------------------------------------------------------------|
| `global.images.envoyProxy.image`       | string | `""` | Full image name (`registry/repo:tag`) for the Envoy Proxy container |
| `global.images.envoyProxy.pullPolicy`  | string | `""` | Image pull policy                                                   |
| `global.images.envoyProxy.pullSecrets` | list   | `[]` | Image pull secrets                                                  |

When any of these are set, the chart generates an `envoyProxy:` block inside the `EnvoyGateway` ConfigMap, wiring into the existing `EnvoyGatewaySpec.envoyProxy` field (added in #7698). The global `imageRegistry` override takes highest precedence, consistent with other chart components.

Full EnvoyProxy defaults (replicas, resources, etc.) can be provided via `config.envoyGateway.envoyProxy`; the image values are merged on top.

Closes #4764.

Signed-off-by: Michael Sommerville <[email protected]>
(cherry picked from commit 8570285)

* add rn and version bump

Signed-off-by: Karol Szwaj <[email protected]>

* fix: respect backend endpoint hostname for health checks (#8929)

* fix: respect backend endpoint hostname for health checks

- Keep BackendTrafficPolicy HTTP health check hostnames as explicit cluster-level hosts, and leave route-derived host fallback to xDS cluster translation.
- Preserve Backend endpoint hostnames as per-endpoint overrides via Endpoint.HealthCheckConfig.hostname, ahead of the route fallback.
- Update gatewayapi/xDS fixtures, release notes, and generated API docs/CRDs for the host selection order.

- go test ./internal/ir
- go test ./internal/xds/translator
- go test ./internal/gatewayapi -run TestTranslate/backendtrafficpolicy
- go test ./internal/gatewayapi -run TestTranslate/(clienttrafficpolicy-http-health-check|envoyextensionpolicy-with-extproc-with-retries|envoyextensionpolicy-with-extproc-with-traffic-features|envoyproxy-accesslog-with-traffic|envoyproxy-tracing-backend-uds|envoyproxy-tracing-backend|securitypolicy-with-jwt-backendcluster|securitypolicy-with-jwt-backendsettings)
- make generate
- make manifests
- git diff --check

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Codex <[email protected]>

* fix gen

Signed-off-by: zirain <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>
Co-authored-by: Codex <[email protected]>
Co-authored-by: zirain <[email protected]>

* update release notes

Signed-off-by: Karol Szwaj <[email protected]>

* fix gen-check

Signed-off-by: Karol Szwaj <[email protected]>

* Revert "feat(chart): Allow configuring envoy proxy image via helm chart (#8785)"

This reverts commit 092cc67.

Signed-off-by: Karol Szwaj <[email protected]>

---------

Signed-off-by: Huabing (Robin) Zhao <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>
Signed-off-by: Michael Sommerville <[email protected]>
Signed-off-by: Karol Szwaj <[email protected]>
Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Huabing (Robin) Zhao <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Co-authored-by: zirain <[email protected]>
Co-authored-by: Michael Sommerville <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Co-authored-by: Codex <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go panic in control plane

4 participants