Skip to content

Commit

Permalink
CI: save a minidump if it hangs on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Jul 20, 2024
1 parent ce65538 commit 41269fd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-sync-old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,13 @@ jobs:
- name: Check p2pool.log
run: |
cd build/RelWithDebInfo
del p2pool.cache
findstr /C:"Synchronization finished successfully" p2pool.log
- name: Archive p2pool.log
uses: actions/upload-artifact@v4
with:
name: p2pool_windows_data_leaks
path: |
build/RelWithDebInfo/*.log
build/RelWithDebInfo/p2pool.*
build/RelWithDebInfo/data/
3 changes: 2 additions & 1 deletion .github/workflows/test-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,13 @@ jobs:
- name: Check p2pool.log
run: |
cd build/RelWithDebInfo
del p2pool.cache
findstr /C:"Synchronization finished successfully" p2pool.log
- name: Archive p2pool.log
uses: actions/upload-artifact@v4
with:
name: p2pool_windows_data_leaks
path: |
build/RelWithDebInfo/*.log
build/RelWithDebInfo/p2pool.*
build/RelWithDebInfo/data/
21 changes: 21 additions & 0 deletions src/memory_leak_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(param);
Sleep(static_cast<DWORD>(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(), 0);

return 0;
}

void minidump_and_crash(size_t delay)
{
CreateThread(nullptr, 0, minidump_and_crash_thread, reinterpret_cast<LPVOID>(delay), 0, nullptr);
}

FORCEINLINE static void add_alocation(void* p, size_t size)
{
if (!track_memory) {
Expand Down
5 changes: 5 additions & 0 deletions src/side_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41269fd

Please sign in to comment.