Skip to content

[BUG] Make file_http_server.h compile on Windows#4300

Closed
thc1006 wants to merge 7 commits into
open-telemetry:mainfrom
thc1006:bugfix/file-http-server-windows-build
Closed

[BUG] Make file_http_server.h compile on Windows#4300
thc1006 wants to merge 7 commits into
open-telemetry:mainfrom
thc1006:bugfix/file-http-server-windows-build

Conversation

@thc1006

@thc1006 thc1006 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #4299
Refs #4287

The problem

FileHttpServer::FileGetSuccess() called std::replace(filename.begin(), filename.end(), ...) on a const std::string &, which yields const iterators, so the _WIN32 branch could not compile. clang 18 and gcc 12 both reject it; it is plain C++, not an MSVC quirk. It survived because no translation unit in the repository includes this installed header, so CI never compiled it on any platform.

The fix

The separator substitution runs on a local copy on Windows; the #else branch binds a reference so other platforms do not pay for a copy. <sstream> is now included directly for std::ostringstream, and <algorithm> (for the Windows-only std::replace) is included under _WIN32; both were previously resolving only because socket_tools.h happens to include them.

Regression protection (added in review)

The header still had no test compiling it, so the fix could regress unnoticed. A compile-only target (file_http_server_header_compile, a CMake OBJECT library and a Bazel cc_library) now includes the header as its only translation unit. CI compiles the POSIX branch on Linux and macOS and the _WIN32 branch on the Windows runners, so a compile-time break in the active platform branch of this header now fails the build. It is compiled, not run. It does not prove direct-include hygiene, since a symbol can still resolve through a transitive header; that is checked separately by the repository's IWYU workflow. The probe uses no symbol from the header on purpose, so its include is marked // IWYU pragma: keep.

Compiling the header for the first time under the maintainer configuration also surfaced pre-existing issues in it that no build had seen before: three extra semicolons after in-class function bodies (errors under -Wextra-semi -Werror) and two single-character string-literal searches, find(".") and find_last_of("."), that clang-tidy performance-faster-string-find flags. Both are fixed here so the header clears the same gates as the rest of the tree rather than raising a limit.

Not in this PR

The header has neighbouring robustness gaps (unchecked tellg(), ignored read() result, non-ASCII filenames, URI query handling) and a path-confinement concern already being handled privately. They are recorded in #4287 rather than folded into this scoped build fix.

Verification

thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Jul 24, 2026
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.24%. Comparing base (29d7a75) to head (4642315).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4300      +/-   ##
==========================================
- Coverage   81.25%   81.24%   -0.01%     
==========================================
  Files         446      446              
  Lines       18872    18872              
==========================================
- Hits        15332    15330       -2     
- Misses       3540     3542       +2     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

thc1006 added a commit to thc1006/opentelemetry-cpp that referenced this pull request Jul 25, 2026
Review of open-telemetry#4300 noted the fix had no regression protection: nothing in
the repository includes this installed header, so every CI job could be
green without the header ever being compiled, which is how the _WIN32
build error survived in the first place.

Add a compile-only target (CMake OBJECT library and Bazel cc_library)
whose sole translation unit includes the header. CI now compiles the
POSIX branch on Linux and macOS and the _WIN32 branch on the Windows
runners, so a future const-iterator std::replace, or any other build
break in this header, fails immediately.

Also add the direct <sstream> include the header needs for
std::ostringstream; like the <algorithm> include, it was resolving only
because socket_tools.h happens to provide it, and the new compile target
is exactly what would surface that.

Fixes open-telemetry#4299

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006 added 5 commits July 25, 2026 16:23
FileGetSuccess() takes the path as a reference to const and then called
std::replace over filename.begin() and filename.end(). Those are const
iterators, so std::replace cannot write through them and the _WIN32
branch does not compile. This is a plain C++ error, not an MSVC quirk:
clang 18 and gcc 12 both reject it when that branch is instantiated.

It went unnoticed because no translation unit in the repository includes
this header, so CI never compiles it on any platform, but it is an
installed header and a downstream Windows build hits it immediately.

The separator substitution now runs on a local copy, and <algorithm> is
included directly rather than arriving by way of socket_tools.h.

Fixes open-telemetry#4299

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Review of open-telemetry#4300 noted the fix had no regression protection: nothing in
the repository includes this installed header, so every CI job could be
green without the header ever being compiled, which is how the _WIN32
build error survived in the first place.

Add a compile-only target (CMake OBJECT library and Bazel cc_library)
whose sole translation unit includes the header. CI now compiles the
POSIX branch on Linux and macOS and the _WIN32 branch on the Windows
runners, so a future const-iterator std::replace, or any other build
break in this header, fails immediately.

Also add the direct <sstream> include the header needs for
std::ostringstream; like the <algorithm> include, it was resolving only
because socket_tools.h happens to provide it, and the new compile target
is exactly what would surface that.

Fixes open-telemetry#4299

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
The new header-compile translation unit is the first thing in the build
to include file_http_server.h, so clang-tidy now lints it and counted
two pre-existing warnings against the ratchet: find() and find_last_of()
called with a single-character string literal. Pass the character
directly so the header is lint-clean under the existing limit rather
than raising it.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
The header-compile translation unit makes the maintainer -Wextra-semi
-Werror configuration compile file_http_server.h for the first time,
turning three pre-existing extra semicolons after in-class function
bodies into errors. Drop them. The probe intentionally uses no symbol
from the header, so mark its include IWYU pragma: keep. Also drop the
unused <iostream> and guard <algorithm> behind _WIN32, where its only
use (std::replace) lives.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
@thc1006
thc1006 force-pushed the bugfix/file-http-server-windows-build branch from aef50bf to 19749b6 Compare July 25, 2026 08:26
Apply cmake-format with the repo config to the file_http_server_header_compile block.
@thc1006
thc1006 marked this pull request as ready for review July 25, 2026 19:12
@thc1006
thc1006 requested a review from a team as a code owner July 25, 2026 19:12
Copilot AI review requested due to automatic review settings July 25, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…er-windows-build

# Conflicts:
#	CHANGELOG.md
@owent

owent commented Jul 26, 2026

Copy link
Copy Markdown
Member

This is dead code and will be removed in #4306 . Maybe this PR can be closed.

@thc1006

thc1006 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #4306, which removes file_http_server.h entirely. That's the better call since the header is unused, so there's nothing left to fix here. Closing.

Thanks @owent for the cleaner fix and @dbarker for landing it.

@thc1006 thc1006 closed this Jul 26, 2026
@thc1006
thc1006 deleted the bugfix/file-http-server-windows-build branch July 26, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] file_http_server.h does not compile on Windows

3 participants