Returning variable by reference requires holding mutex

73 views Asked by At

I am building Envoy v1.29.1 from source.

When running the command bazel build -c opt envoy --config=clang, I get the following error:

ERROR: /home/test/envoy/source/common/stats/BUILD:240:17: Compiling source/common/stats/thread_local_store.cc failed: (Exit 1): clang failed: error executing command (from target //source/common/stats:thread_local_store_lib) /usr/lib/llvm-18/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer ... (remaining 194 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
In file included from source/common/stats/thread_local_store.cc:1:
./source/common/stats/thread_local_store.h:426:10: error: returning variable 'central_cache_' by reference requires holding mutex 'parent_.lock_' [-Werror,-Wthread-safety-reference-return]
  426 |                 return central_cache_;
      |                        ^
1 error generated.
Target //source/exe:envoy-static failed to build
FAILED: Build did NOT complete successfully

I have clang18 and gcc11 installed on my ubuntu 22.04 system.

I tried setting the flags --cxxopt="-Wthread-safety-reference", --cxxopt="-Werror" in bazel build command but it didn't work.

0

There are 0 answers