std::cerr redirection hangs on Windows
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- cpp
- Ambito
- operating-systems, testing
Direzione di ricerca
Inizia eseguendo la riproduzione catch_repro.zip allegata con CMake su Windows, generando un progetto Visual Studio ed eseguendolo con -r quiet. Esamina il comportamento del reindirizzamento di std::cerr attorno a shouldRedirectStdOut, startRedirect e stopRedirect, usando lo stack trace del debugger riportato come punto del guasto. Il lavoro è completato quando la riproduzione non si blocca più, mentre l’output reindirizzato rimane disponibile tramite Catch::cout().
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
With shouldRedirectStdOut enabled, Windows can hang on writing to std::cerr
Expected behavior
No hangs should happen
Reproduction steps
Steps to reproduce the bug.
This is a really obnoxious one to track down but I was able to create a reproduction that reproduces it....sometimes (catch_repro.zip). You can run CMake on it to generate a visual studio project and then run the resulting exe with the -r quiet argument. You'll know if it hits the actual issue if the program is hung and attaching a debugger reveals that it is blocked with the following stack trace (I had better luck today running from the command prompt and then using visual studio to attach a debugger once I saw it hanging):
ucrtbased.dll!_lock_file(_iobuf * stream) Line 141 C++
msvcp140d.dll!std::basic_filebuf<char,std::char_traits<char>>::_Lock() Line 376 C++
catch_repro.exe!std::basic_ostream<char,std::char_traits<char>>::_Sentry_base::_Sentry_base(std::basic_ostream<char,std::char_traits<char>> & _Ostr) Line 78 C++
catch_repro.exe!std::basic_ostream<char,std::char_traits<char>>::sentry::sentry(std::basic_ostream<char,std::char_traits<char>> & _Ostr) Line 96 C++
catch_repro.exe!std::_Insert_string<char,std::char_traits<char>,unsigned __int64>(std::basic_ostream<char,std::char_traits<char>> & _Ostr, const char * const _Data, const unsigned __int64 _Size) Line 480 C++
catch_repro.exe!std::operator<<<char,std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> & _Ostr, const std::basic_string_view<char,std::char_traits<char>> _Str) Line 1782 C++
catch_repro.exe!fleece_Catch::CaseListReporter::sectionStarting(const Catch::SectionInfo & _sectionInfo) Line 466 C++
catch_repro.exe!Catch::RunContext::sectionStarted(Catch::StringRef sectionName, const Catch::SourceLineInfo & sectionLineInfo, Catch::Counts & assertions) Line 5917 C++
catch_repro.exe!Catch::Section::Section(Catch::SectionInfo && info) Line 6316 C++
catch_repro.exe!Catch::NWayMethodTestInvoker<`anonymous namespace'::CATCH2_INTERNAL_TEST_2>::invoke() Line 18 C++
catch_repro.exe!Catch::TestCaseHandle::invoke() Line 7163 C++
catch_repro.exe!Catch::RunContext::invokeActiveTestCase() Line 6161 C++
catch_repro.exe!Catch::RunContext::runCurrentTest() Line 6124 C++
catch_repro.exe!Catch::RunContext::runTest(const Catch::TestCaseHandle & testCase) Line 5822 C++
catch_repro.exe!Catch::`anonymous namespace'::TestGroup::execute() Line 1253 C++
catch_repro.exe!Catch::Session::runInternal() Line 1473 C++
catch_repro.exe!Catch::Session::run() Line 1405 C++
catch_repro.exe!Catch::Session::run<char>(int argc, const char * const * argv) Line 4937 C++
Platform information:
- OS: Windows 10.0.10945 Pro
- Compiler+version: MSVC 19.41.34120.0
- Catch version: v3.7.1
Additional context
The underlying issue here, in my opinion, is a weird decision by the Microsoft C++ runtime. Whenever you write to some sort of stream, the underlying rdbuf is locked and then unlocked when the write is done. Seems sane enough except that the way it does it is by asking the stream for its rdbuf in the constructor, locking it, and then asking the stream for its rdbuf again in the destructor and unlocking that. My theory is that since Catch is so wildly swapping the rdbuf back and forth, it might be switching the rdbuf between the constructor and destructor while another thread is writing and thus causing the original rdbuf to be locked forever. I experimented by having catch do the same locking when swapping the rdbuf but that did not solve the issue. In fact the only thing that DOES work is commenting out the stopRedirect logic so that only startRedirect actually does anything. Everything I want to be logged is still logged due to Catch using Catch::cout() instead of std::cout to log so I am willing to patch it that way, but this problem is bothering me quite a bit.
Sorry this isn't quite a minimal project as it uses a custom reporter (slightly altered console reporter) and a custom invoker to allow variations on a test in different "modes" but hopefully it is minimal enough.
- Lingua principale
- C++
- Stelle
- 21.6k
- Fork
- 3.4k
- Merge medio
- 3g 12h
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di catchorg/Catch2
-
catch_discover_tests fails for Windows test executables run under Wine since v3.15.2Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 2 giorni
-
catch_discover_tests passes all EXTRA_ARGS as one argumentForse già presa @CyberKun l’ha presa 11 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
catchorg/Catch2#3239 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Not seeing some error messages from fakeit in jetbrains riderForse già presa @Amanpal9 l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
catchorg/Catch2#3228 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
catch_discover_tests fails for Emscripten/WASM tests since v3.16.0Forse già presa @nafiurahman00 l’ha presa 8 giorni fa. ApertaExtras
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
catchorg/Catch2#3241 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di catchorg/Catch2
Issue simili
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
cloudflare/workerd#8963 ·
I maintainer di solito rispondono entro 1 giorno
-
Android Bug Core Drape
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
organicmaps/organicmaps#14449 ·
I maintainer di solito rispondono entro 1 giorno
-
comp-codecs
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ClickHouse/ClickHouse#135159 ·
I maintainer di solito rispondono entro 1 giorno
-
difficulty:easy func:python os:windows prio:high type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2029 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
ardazishvili/Sota#114 ·
I maintainer di solito rispondono entro 1 giorno