@@ -637,4 +637,62 @@ TEST_F(LoggingTestLogFileRace, testCrtLoggerRaceSingleLogger)
637637 bool success = futures[i].get ();
638638 ASSERT_TRUE (success);
639639 }
640- }
640+ }
641+
642+ // TEST_F(LoggingTestLogFileRace, testCrtShutdownUseAfterFree)
643+ // {
644+ // /*
645+ // * Tests use-after-free during CRT shutdown when threads are actively logging.
646+ // * Simulates scenario where logger is shutdown while threads are still using it.
647+ // */
648+ // static const size_t PARALLEL_COUNT = 8;
649+ // std::atomic<bool> keepLogging{true};
650+ // std::atomic<bool> startLogging{false};
651+ // Aws::Vector<std::future<void>> futures(PARALLEL_COUNT);
652+ //
653+ // {
654+ // CRTLogSystemInterface* rawPtr = nullptr;
655+ // auto crtLogger = Aws::MakeShared<DefaultCRTLogSystem>(AllocationTag, LogLevel::Info);
656+ // rawPtr = crtLogger.get();
657+ // InitializeCRTLogging(crtLogger);
658+ //
659+ // // Start threads that will actively log
660+ // for(size_t i = 0; i < PARALLEL_COUNT; ++i)
661+ // {
662+ // futures[i] = std::async(std::launch::async, [&keepLogging, &startLogging, rawPtr, i]() {
663+ // // Wait for signal to start logging
664+ // while (!startLogging.load() && keepLogging.load()) {
665+ // std::this_thread::sleep_for(std::chrono::microseconds(100));
666+ // }
667+ //
668+ // // Continuously log until told to stop
669+ // while (keepLogging.load()) {
670+ // LogOnCRTLogSystemInterfaceWithoutVaArgs(rawPtr, LogLevel::Info, "CRTShutdownTest", "Active logging from thread %zu", i);
671+ // std::this_thread::sleep_for(std::chrono::microseconds(10));
672+ // }
673+ // });
674+ // }
675+ //
676+ // // Start active logging
677+ // startLogging = true;
678+ //
679+ // // Let threads log for a brief moment
680+ // std::this_thread::sleep_for(std::chrono::milliseconds(10));
681+ //
682+ // } // crtLogger goes out of scope here
683+ //
684+ // // Shutdown CRT logging while threads are still active
685+ // ShutdownCRTLogging();
686+ //
687+ // // Uncomment this if you want to see the use after free error every single time
688+ // //std::this_thread::sleep_for(std::chrono::milliseconds(10));
689+ //
690+ // keepLogging = false;
691+ // for(size_t i = 0; i < PARALLEL_COUNT; ++i)
692+ // {
693+ // futures[i].wait();
694+ // }
695+ //
696+ //
697+ // SUCCEED();
698+ // }
0 commit comments