Skip to content

Commit

Permalink
network: fix tsan test flake (envoyproxy#32631)
Browse files Browse the repository at this point in the history
Fixes envoyproxy#32527

Signed-off-by: Greg Greenway <[email protected]>
  • Loading branch information
ggreenway authored Feb 29, 2024
1 parent f7352b3 commit 5728604
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions source/common/network/address_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,18 @@ std::string Ipv4Instance::sockaddrToString(const sockaddr_in& addr) {
}

namespace {
bool force_ipv4_unsupported_for_test = false;
std::atomic<bool> force_ipv4_unsupported_for_test = false;
}

Cleanup Ipv4Instance::forceProtocolUnsupportedForTest(bool new_val) {
bool old_val = force_ipv4_unsupported_for_test;
force_ipv4_unsupported_for_test = new_val;
return {[old_val]() { force_ipv4_unsupported_for_test = old_val; }};
bool old_val = force_ipv4_unsupported_for_test.load();
force_ipv4_unsupported_for_test.store(new_val);
return {[old_val]() { force_ipv4_unsupported_for_test.store(old_val); }};
}

absl::Status Ipv4Instance::validateProtocolSupported() {
static const bool supported = SocketInterfaceSingleton::get().ipFamilySupported(AF_INET);
if (supported && !force_ipv4_unsupported_for_test) {
if (supported && !force_ipv4_unsupported_for_test.load(std::memory_order_relaxed)) {
return absl::OkStatus();
}
return absl::FailedPreconditionError("IPv4 addresses are not supported on this machine");
Expand Down Expand Up @@ -335,18 +335,18 @@ Ipv6Instance::Ipv6Instance(absl::Status& status, const sockaddr_in6& address, bo
}

namespace {
bool force_ipv6_unsupported_for_test = false;
std::atomic<bool> force_ipv6_unsupported_for_test = false;
}

Cleanup Ipv6Instance::forceProtocolUnsupportedForTest(bool new_val) {
bool old_val = force_ipv6_unsupported_for_test;
force_ipv6_unsupported_for_test = new_val;
return {[old_val]() { force_ipv6_unsupported_for_test = old_val; }};
bool old_val = force_ipv6_unsupported_for_test.load();
force_ipv6_unsupported_for_test.store(new_val);
return {[old_val]() { force_ipv6_unsupported_for_test.store(old_val); }};
}

absl::Status Ipv6Instance::validateProtocolSupported() {
static const bool supported = SocketInterfaceSingleton::get().ipFamilySupported(AF_INET6);
if (supported && !force_ipv6_unsupported_for_test) {
if (supported && !force_ipv6_unsupported_for_test.load(std::memory_order_relaxed)) {
return absl::OkStatus();
}
return absl::FailedPreconditionError("IPv6 addresses are not supported on this machine");
Expand Down

0 comments on commit 5728604

Please sign in to comment.