From 37bf8554fcc5e07a1a56d521ffd63a168b5a982c Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Sat, 20 Jul 2024 12:49:00 +0200 Subject: [PATCH] CI: save a minidump if it hangs on shutdown --- .github/workflows/test-sync-old.yml | 4 +++- .github/workflows/test-sync.yml | 4 +++- src/memory_leak_debug.cpp | 21 +++++++++++++++++++++ src/side_chain.cpp | 5 +++++ src/util.h | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-sync-old.yml b/.github/workflows/test-sync-old.yml index 072efc9..3e4f7a2 100644 --- a/.github/workflows/test-sync-old.yml +++ b/.github/workflows/test-sync-old.yml @@ -415,12 +415,14 @@ jobs: - name: Check p2pool.log run: | cd build/RelWithDebInfo + Remove-Item p2pool.cache -Force findstr /C:"Synchronization finished successfully" p2pool.log - name: Archive p2pool.log + if: '!cancelled()' uses: actions/upload-artifact@v4 with: name: p2pool_windows_data_leaks path: | - build/RelWithDebInfo/*.log + build/RelWithDebInfo/p2pool.* build/RelWithDebInfo/data/ diff --git a/.github/workflows/test-sync.yml b/.github/workflows/test-sync.yml index efaa665..3fbe5b0 100644 --- a/.github/workflows/test-sync.yml +++ b/.github/workflows/test-sync.yml @@ -436,12 +436,14 @@ jobs: - name: Check p2pool.log run: | cd build/RelWithDebInfo + Remove-Item p2pool.cache -Force findstr /C:"Synchronization finished successfully" p2pool.log - name: Archive p2pool.log + if: '!cancelled()' uses: actions/upload-artifact@v4 with: name: p2pool_windows_data_leaks path: | - build/RelWithDebInfo/*.log + build/RelWithDebInfo/p2pool.* build/RelWithDebInfo/data/ diff --git a/src/memory_leak_debug.cpp b/src/memory_leak_debug.cpp index fe7c8f9..86ff686 100644 --- a/src/memory_leak_debug.cpp +++ b/src/memory_leak_debug.cpp @@ -137,6 +137,27 @@ void show_top_10_allocations() VirtualFree(buf, 0, MEM_RELEASE); } +static DWORD WINAPI minidump_and_crash_thread(LPVOID param) +{ + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); + + const size_t delay = reinterpret_cast(param); + Sleep(static_cast(delay)); + + HANDLE h = CreateFile(TEXT("p2pool.dmp"), GENERIC_ALL, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), h, MiniDumpWithHandleData, nullptr, nullptr, nullptr); + CloseHandle(h); + + TerminateProcess(GetCurrentProcess(), 123); + + return 0; +} + +void minidump_and_crash(size_t delay) +{ + CreateThread(nullptr, 0, minidump_and_crash_thread, reinterpret_cast(delay), 0, nullptr); +} + FORCEINLINE static void add_alocation(void* p, size_t size) { if (!track_memory) { diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 600e8b0..820912f 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -2185,6 +2185,11 @@ void SideChain::prune_old_blocks() m_pool->print_hosts(); m_pool->stop(); + +#ifdef DEV_TRACK_MEMORY + // Give it 1 minute to shut down, otherwise save a minidump + minidump_and_crash(60 * 1000); +#endif } #endif } diff --git a/src/util.h b/src/util.h index 9341b0c..752450c 100644 --- a/src/util.h +++ b/src/util.h @@ -358,6 +358,7 @@ FORCEINLINE bool get_dns_txt_records(const std::string& host, T&& callback) { re #ifdef DEV_TRACK_MEMORY void show_top_10_allocations(); +void minidump_and_crash(size_t delay); #endif } // namespace p2pool