From b68f7dc1f44e4c8590d37b433a1f3a471fe688de Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Wed, 22 Jul 2026 18:48:13 +0100 Subject: [PATCH] fix(telemetry): guard MetricMacros.h against WinSock1/Boost.Asio clash On Windows the telemetry unit test src/tests/libxrpl/telemetry/MetricMacros.cpp fails to compile with boost/asio/detail/socket_types.hpp C1189 "WinSock.h has already been included". Root cause traced with clang -E -H: MetricMacros.h pulls MetricsRegistry.h -> OTel spin_lock_mutex.h, which defines _WINSOCKAPI_ and includes (WinSock 1); it then pulls ServiceRegistry.h -> , whose socket_types.hpp requires winsock2.h first. Production consumers (RCLConsensus.cpp, PerfLogImp.cpp) happen to include Boost.Asio via other xrpld headers first, so only the test TU -- which includes MetricMacros.h first -- hit it. Pre-include boost/asio/detail/socket_types.hpp under _MSC_VER at the top of the header so winsock2.h wins for every consumer. Mirrors the existing guard in MetricsRegistry.cpp. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/xrpld/telemetry/MetricMacros.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/xrpld/telemetry/MetricMacros.h b/src/xrpld/telemetry/MetricMacros.h index 827213c393..940f916de5 100644 --- a/src/xrpld/telemetry/MetricMacros.h +++ b/src/xrpld/telemetry/MetricMacros.h @@ -101,6 +101,18 @@ * tasks/metric-macro-plan.md. */ +// On Windows, OTel's spin_lock_mutex.h (transitively included from +// MetricsRegistry.h) defines _WINSOCKAPI_ and includes , which +// pulls in WinSock 1. ServiceRegistry.h below then includes , +// whose socket_types.hpp requires winsock2.h first and errors out if WinSock 1 +// arrived earlier. Pre-including boost's socket types header here gets +// winsock2.h in before the OTel headers, so any translation unit that includes +// MetricMacros.h first (e.g. the telemetry unit tests) still compiles. The +// production MetricsRegistry.cpp carries the same guard. +#ifdef _MSC_VER +#include +#endif + #include // IWYU pragma: keep #include // IWYU pragma: keep