Fix MSAN warnings on clang-18 due to destruction order issues #38187
+24
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commit Message:
This change contains multiple MSAN fixes detected by clang-18. They all in different places, but all of them are caused by a similar issue.
In C++ members of the class are always created in the same order in which they are declared in the class. And they are always destroyed in reverse order. So the first memeber of the class is created first and destroyed last.
When there are interdependencies between the members of a class the order of destruction becomes important. We typically don't want to access data of the already destroyed members in destructors of the members that are being destroyed.
MSAN on clang-18 detected a bunch of cases where we access some fields after they were destroyed. In all but one case, issues happens in tests only and not in the Envoy binary. There is one case where a similar problem occurs in regular Envoy code, but this issue is benign, because we are accessing an atomic variable that does not trully get destroyed.
So, all-in-all, these are not serious issues, but we want to fix it to make clang MSAN tests happy on new LLVM toolchain.
I also sharded a few tests, because it was the only way I could actually run them through the end within given timeouts on my workstation. Hopefully that's not a problem.
Additional Description: Related to the work done in #37911
Risk Level: Low
Testing: msan checks with clang-18
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a
+cc @phlax