Skip to content

msvc: replace debug CRT GUI popups with stderr output - #23400

Closed
vszakats wants to merge 19 commits into
curl:masterfrom
vszakats:msc-crtdbg-avoid-gui
Closed

vszakats wants to merge 19 commits into
curl:masterfrom
vszakats:msc-crtdbg-avoid-gui

Conversation

@vszakats

@vszakats vszakats commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

When a curl binary is built with Visual Studio in debug mode, it uses
the matching, debug-enabled CRT. The debug CRT by default pops up an
interactive GUI dialog by default, also on CI machines, both on AppVeyor
CI and GHA, on assert() and other low-level failures. This causes the
CI job to appear hung, with nothing printed to the CI log, invisibly
waiting for someone clicking on a GUI MessageBox. On a remote/headless
CI machine this is unworkable. The job then quits on timeout, after
blocking other queued tasks (for 1 hour on AppVeyor CI, 10-15 minutes in
GHA/windows).

To make such failures CI-friendly, fix by configuring this behavior in
curl.exe, servers.exe and unit test binaries, to output all errors
to stderr, and to OutputDebugString(), overiding the GUI popup.

This can save a lot of hair-pulling.

Example output, after this patch:

Assertion failed: r == 10, file C:\projects\curl\tests\libtest\first.c, line 272
   abort() has been called

Note, the default debug CRT behavior depends on a number of things, e.g.
on a Server Core (or similar) Windows edition, or when run under a
debugger. Assuming the default behavior is the expected one in most
cases, this patch only reconfigures it for builds made in the curl CI.
If you want to enable it, set the CURL_CI env to non-empty at
configure time, or build with the -DCURL_DEBUG_MSVC_CRTDBG C macro.

This issue does not apply to mingw-w64 builds, as tested with both UCRT
and MSVCRT. They output the assert text to the CI logs out-of-the-box.

Refs:
https://learn.microsoft.com/cpp/c-runtime-library/reference/crtsetreportfile
https://learn.microsoft.com/cpp/c-runtime-library/reference/crtsetreportmode
https://learn.microsoft.com/cpp/c-runtime-library/reference/set-error-mode

Ref: #23336
Ref: edfa537 #16456
Ref: #14854
Cherry-picked from #23306


When a curl binary is built with Visual Studio in debug mode, it uses
the matching, debug-enabled CRT. The debug CRT by default pops up an
interactive GUI popup by default, also on CI machines, e.g. on AppVeyor
CI, on `assert()` and other low-level failures. This causes the CI job
to appear hung, with nothing printed to the CI log, waiting on someone
clicking on a GUI MessageBox. On a CI machine this is not desired. The
job then quits on timeout, blocking other queued tasks (for 1 hours on
AppVeyor CI).

To make such failures CI-friendly, fix it by configuring this behavior
in curl.exe, servers.exe and unit test binaries, to output all errors to
stderr, overiding the GUI popup.

This can potentially save a lot of hair-pulling.

Example output, after this patch:
```
Assertion failed: r == 10, file C:\projects\curl\tests\libtest\first.c, line 272
   abort() has been called
```

In theory, this issue may also apply to mingw-w64 builds (they use the
same UCRT as VS2015+ builds), but I could not make the configuation code
link correctly. (in practice I haven't seen mingw-w64 builds hanging in
CI, but that's more like a coincidence.) Feel free to extend this to
mingw-w64 if there is a sensible way to do it.

Refs:
https://learn.microsoft.com/cpp/c-runtime-library/reference/crtsetreportfile
https://learn.microsoft.com/cpp/c-runtime-library/reference/crtsetreportmode
https://learn.microsoft.com/cpp/c-runtime-library/reference/set-error-mode

Ref: curl#23336
Ref: edfa537 curl#16456
Cherry-picked from curl#23306
@vszakats
vszakats marked this pull request as draft October 14, 2026 16:49
@vszakats vszakats added Windows Windows-specific CI Continuous Integration labels Oct 14, 2026
@jay

jay commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Assuming the default behavior is the expected one in most cases, this patch only reconfigures it for builds done in the curl CI

I prefer them the popups especially the one that lets me attach Visual Studio to a curld process that was not running in Visual Studio. Sometimes though I have used the reportmode. I see in my notes that _CRT_ERROR works (or used to work..) for DEBUGASSERT and _CRT_ASSERT works for straight assert, which doesn't make much sense to me since DEBUGASSERT in debug builds is assert(). Also I have the modes OR'd with _CRTDBG_MODE_DEBUG to send the output to the VS window as well. like this

  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);

Another thing is crtdbg usually needs to be included first to get line numbers for memory leaks, /FI"crtdbg.h" and IIRC it may interfere with curl memory tracking or can give extra warnings because of the stuff it overrides so it's not really a clean solution. For the file and line numbers I have this in my notes:

/*
For file and line numbers in libcurl:
- Add _CRTDBG_MAP_ALLOC; to preprocessor definitions.
- Add crtdbg.h; to forced includes.
*/

then you could enable automatic leak check at program end if necessary,
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

...but that finds a lot of "leaks" that may not be curl leaks, maybe in openssl etc which you'd need the same crtdbg and map things for every library to find the leaks, if there are any. So it's of limited use here but I figure you may be interested on the background.

@vszakats

vszakats commented Oct 14, 2026 •

Copy link
Copy Markdown
Member Author

@jay: The extra output to the debugger cannot hurt AFAICT, and
may help when testing a binary locally for example; I enabled it now.

As for the place of include for crtdbg.h: based on the UCRT copy
I have at hand, the memory function overrides only happen if
_CRTDBG_MAP_ALLOC is explicitly defined. Doing this as-is would
likely be a broken or at best weird build. I think if someone wants to do
this, it can work by passing /FI"crtdbg.h", regardless of where we include
it (it's a #pragma once header). It likely needs to be a Debug but
non-debug-enabled build with the former macro set too, and comes
with the caveats you mentioned. This works just the same after this
patch, I think even with CURL_DEBUG_MSVC_CRTDBG defined.

Nothing else stands out in that header that would cause issues, on
a quick skim at least.

@testclutch

This comment was marked as outdated.

@vszakats
vszakats marked this pull request as ready for review October 14, 2026 22:44
@vszakats
vszakats requested a lite review from Copilot October 14, 2026 22:44

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.

@vszakats

Copy link
Copy Markdown
Member Author

@aisle-analyzer

@aisle-research-bot

aisle-research-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

✅ Aisle scan complete — no security issues detected.

Aisle supplements but does not replace security review.

Last updated on: 2026-10-14T22:46:13Z

@vszakats vszakats mentioned this pull request Oct 14, 2026
9 of 10 tasks
@jay

jay commented Oct 15, 2026

Copy link
Copy Markdown
Member

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

I thought we got free copilot credits for the organization but looking into it just now it looks like we get $15 in credits per individual and org billing says AI usage not found. I don't know if that's expected or not.. So we as individuals "pay" the AI out of our accounts, and not the organization?

@jay
jay requested a balanced review from Copilot October 15, 2026 07:21

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.

🟢 Approval recommended

The changes are narrowly guarded, cover the intended entry points, and have no identified blocking issues.

0 open findings

🧠 Review effort: Balanced

@vszakats
vszakats force-pushed the msc-crtdbg-avoid-gui branch from 1bd0b43 to 8dbbb35 Compare October 15, 2026 07:45
@vszakats

vszakats commented Oct 15, 2026 •

Copy link
Copy Markdown
Member Author

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

I thought we got free copilot credits for the organization but looking into it just now it looks like we get $15 in credits per individual and org billing says AI usage not found. I don't know if that's expected or not.. So we as individuals "pay" the AI out of our accounts, and not the organization?

I find it super opaque, as of now, if my personal account does not have
a Copilot plan, even the option is missing, including in the curl repo.
GitHub gave me Pro+ for the duration of the GitHub Secure Open Source
Fund program. I'm thankful for that (on behalf of curl and libssh2). It
expired in early September. When re-applying, I ended up with Pro. Its
monthly credits, with my light use for reviews only (curl and some
libssh2), lasted 5 days. Remaining tokens lasted 7 more days for the
occasional Lite PR reviews.

I had found Balanced reviews very useful in both projects. 5/12 days of
Balanced/Lite reviews is better than nothing, but the work is
continuous, so the option is definitely missing now, for example.

Thanks for pinging Copilot for this PR!

@vszakats vszakats closed this in bc22977 Oct 15, 2026
@vszakats
vszakats deleted the msc-crtdbg-avoid-gui branch October 15, 2026 08:34
Comment thread projects/Windows/generate.bat Resolved
vszakats added a commit that referenced this pull request Oct 15, 2026
vszakats added a commit that referenced this pull request Oct 18, 2026
- in jobs building tests, also run them.
- to maintain CI cycle times, only run unit tests by default, and run
  all (supported) tests in just one job, carefully selected to be the
  one running them the fastest.
  Per job, it takes ~15 seconds to run ~80 unit tests.
  It takes 5 minutes to run all (~1600) tests. Total job time 5.5-6
  minutes.
  If the full test run turns out to be annoying or grow slow, we disable
  or limit it to a subset of tests.
- run tests with `-j10` parallelism. It results in the fastest runs,
  based on tests.
- to avoid the MSBuild test breaker heuristics, and to improve
  performance, run tests by directly invoking `runtests.pl` (not via
  CMake -> MSBuild -> `runtests.pl`).
  It saves 10-40 seconds per full test run.
- when running directly via `runtests.pl`, exclude test 1119 and 1167.
  It's not compatible with Visual Studio generator builds.
- run the artifact upload in parallel with running tests.

Running Windows tests in multiple environments makes it more likely they
can run on local machines, too, also making them easier to debug.
AppVeyor also supports remote access via RDP, which may help debugging
notorious Windows issues live, with some luck of reproducing it in a run
with RDP access explicitly enabled beforehand.

Fixes/improvements via this PR, merged separately:

dc99e12 #23467 processhelp.pm: improve task info in trace output (Windows)
70f3f85 #23471 test1488: drop unused C preprocessor logic
af9d2dd #23336 cmake: fix preconditions for option `CURL_STATIC_CRT=ON`
adf8b78 #23428 setopt: fix setting `CURLWS_NOAUTOPONG` with compilers lacking C99 bool type
780405b #23416 tests: add `--dump-module-paths` debug option (Windows)
bc22977 #23400 msvc: replace debug CRT GUI popups with stderr output
87a1dc7 #23396 appveyor: minor improvements
67f3510 #23381 runtests: add `-S` option to show success logs
e9af987 #23378 tests/server: fix crashing with VS2013 and earlier
8cdee8a #23377 lib557: exclude three floating point test cases for VS2013 and earlier
1aac64a #23375 test1119, 1167: disable MSYS2 argument conversion narrowly
49f003f #23337 unit1664: add workaround for VS2019 16.3 - VS2022 17.4 x64 miscompile
b8f71d6 #23345 test428: skip when running on older MSYS2 versions
2f3f99d #23339 test1119, 1167: disable MSYS2 argument conversion
098d3a0 #23332 runtests: unset `CURL_MEMDEBUG` for curl requests made to the CI API
d3e7caf #23335 GHA/windows: drop unused `-ac` runtests options
2874cc6 #23317 mqttd: work around bogus VS2019 32-bit compiler warning
e8adc72 #23315 schannel: fix guard for old MSVC workaround

Follow-up to 41198e0 #20390

Closes #23306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration cmdline tool tests Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

4 participants