Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 11, 2026

Fixes potential crashes or hangs during process shutdown due to race conditions in vector destructor execution.

Noticed while reviewing #122989

Description

Replaced std::vector<const char*> g_argvCreateDump static variable with a fixed-size array const char* g_argvCreateDump[MAX_ARGV_ENTRIES] (32 entries) in both CoreCLR and NativeAOT implementations. The vector's destructor can cause race conditions during process shutdown, potentially leading to crashes or hangs.

Changes:

  • Replaced vector with const char* g_argvCreateDump[MAX_ARGV_ENTRIES] in src/coreclr/pal/src/thread/process.cpp
  • Updated PROCBuildCreateDumpCommandLine to use array indexing instead of push_back()
  • Updated PROCCreateCrashDumpIfEnabled to copy array elements manually and added bounds check for siginfo processing
  • Updated PAL_GenerateCoreDump to use local fixed-size array
  • Removed #include <vector> dependency from process.cpp
  • Updated src/coreclr/nativeaot/Runtime/unix/PalCreateDump.cpp to use assert instead of runtime check for consistency
  • Used _ASSERTE for bounds checking instead of runtime checks, matching the established pattern

Customer Impact

Prevents potential crashes or hangs during process shutdown due to race conditions in vector destructor execution, particularly in crash dump generation scenarios.

Regression

No. This addresses a pre-existing race condition.

Testing

CoreCLR and NativeAOT components build successfully with no errors or warnings. Asserts verify that array bounds are respected during development and testing.

Risk

Low. Changes are isolated to crash dump generation code path. Pattern is consistent between CoreCLR and NativeAOT implementations. Asserts will catch any programming errors during development while not adding runtime overhead in release builds.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Refactor process.cpp to remove vector dependency Refactor process.cpp to eliminate vector dependency and shutdown race conditions Jan 11, 2026
Copilot AI requested a review from jkotas January 11, 2026 16:20
Changed runtime bounds checks to _ASSERTE calls since MAX_ARGV_ENTRIES (32) is large enough that these conditions should never be true in practice. This matches the pattern used in NativeAOT's PalCreateDump.cpp.

Co-authored-by: jkotas <[email protected]>
Moved the `argv[argc] = nullptr;` assignment outside the if/else block to eliminate duplication, as suggested by @jkotas.

Co-authored-by: jkotas <[email protected]>
Copilot AI requested a review from jkotas January 12, 2026 17:15
@jkotas jkotas marked this pull request as ready for review January 14, 2026 02:33
Copilot AI review requested due to automatic review settings January 14, 2026 02:33
@jkotas jkotas requested review from noahfalk and steveisok January 14, 2026 02:33
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the crash dump generation code in process.cpp to eliminate the dependency on std::vector and prevent race conditions during process shutdown. The vector's destructor can cause issues when invoked during shutdown, potentially leading to crashes or hangs.

Changes:

  • Replaced std::vector<const char*> g_argvCreateDump with fixed-size array const char* g_argvCreateDump[MAX_ARGV_ENTRIES] (32 entries)
  • Updated all related functions to use array indexing instead of vector operations
  • Removed #include <vector> dependency
  • Added compile-time assertions for bounds checking following the NativeAOT pattern

…NativeAOT with assert pattern

- Added bounds check `&& argc < MAX_ARGV_ENTRIES` before processing siginfo in process.cpp
- Changed NativeAOT PalCreateDump.cpp to use assert instead of runtime check, consistent with the pattern established in earlier review feedback

Co-authored-by: jkotas <[email protected]>
Copilot AI requested a review from jkotas January 14, 2026 03:13
@jkotas jkotas merged commit 00c5580 into main Jan 14, 2026
100 checks passed
@hoyosjs hoyosjs deleted the copilot/refactor-process-cpp-dependency branch January 14, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants