Skip to content

golang: lock setDrainConnectionUponCompletion and clarify getStringValue

1efcb6f
Select commit
Loading
Failed to load commit list.
Open

golang: replace per-cgo-call destroy mutex with std::atomic<bool> #44662

golang: lock setDrainConnectionUponCompletion and clarify getStringValue
1efcb6f
Select commit
Loading
Failed to load commit list.
CI (Envoy) / Mobile/CC skipped Apr 29, 2026 in 0s

Check was skipped

This check was not triggered in this CI run

Details

Request (pr/44662/main@1efcb6f)

wdauchy @wdauchy 1efcb6f #44662 merge main@099a9d7

golang: replace per-cgo-call destroy mutex with std::atomic

Commit Message:
Every CAPI call from Go into the C++ filter (getHeader, copyHeaders, setHeader, addData, continueStatus, ...) was acquiring Filter::mutex_ purely to read the has_destroyed_ flag. Off-thread Go callers paid the cost twice: once at the entry point and again inside the dispatcher-post lambda's hasDestroyed() check. On uncontended fast paths this is two atomic compare-and-swap operations and a memory fence per call, on top of the cgo boundary cost that's already paid for every API call.

Make has_destroyed_ a std::atomic with release-store on the single onDestroy() write and acquire-load on the read path. This turns the destroy check into a plain atomic load (free on x86, an ldar on ARM) and removes the mutex acquisition from 18 CAPI entry points and ~12 dispatcher-post lambdas. The Filter is kept alive across cgo calls by the shared_ptr taken at the cgo wrapper layer (cgo.cc), so seeing a false-then-true transition mid-call is benign; the lambdas all also check weak_from_this() expiration.

Filter::mutex_ is retained on the five CAPI methods that write to req_->strValue (getStringValue, getDynamicMetadata, getStringFilterState, getStringProperty, getSecret) to keep the existing serialization between off-thread Go callers writing to the shared scratch buffer.

No behaviour change for unit/integration tests; existing onDestroy() ordering and the post-destroy CAPIFilterIsDestroy semantics are preserved.

Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Environment

Request variables

Key Value
ref 1ae66d0
sha 1efcb6f
pr 44662
base-sha 099a9d7
actor wdauchy @wdauchy
message golang: replace per-cgo-call destroy mutex with std::atomic...
started 1777438809.132319
target-branch main
trusted false
Build image

Container image/s (as used in this CI run)

Key Value
default docker.io/envoyproxy/envoy-build:86873047235e9b8232df989a5999b9bebf9db69c
mobile docker.io/envoyproxy/envoy-build:mobile-86873047235e9b8232df989a5999b9bebf9db69c
Version

Envoy version (as used in this CI run)

Key Value
major 1
minor 39
patch 0
dev true