Skip to content

Fix INVALID_PARAMETER crash in ThreadPoolSchedulerWin::Post by adding null pointer guards#15154

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-15099-2
Closed

Fix INVALID_PARAMETER crash in ThreadPoolSchedulerWin::Post by adding null pointer guards#15154
Copilot wants to merge 1 commit intomainfrom
copilot/fix-15099-2

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 18, 2025

This PR fixes a Watson failure crash caused by INVALID_PARAMETER (c000000d) in Microsoft.ReactNative.dll!Mso::ThreadPoolSchedulerWin::Post. The crash occurs when ::SubmitThreadpoolWork() is called with a null or invalid TP_WORK handle.

Root Cause

The crash happens when:

  1. CreateThreadpoolWork() fails during construction and returns nullptr
  2. The object is used during/after destruction
  3. Memory corruption affects the m_threadPoolWork member

The stack trace shows the crash originates from line 157 in threadPoolScheduler_win.cpp where ::SubmitThreadpoolWork(m_threadPoolWork.get()) is called without validating the handle.

Changes Made

Added defensive null pointer checks in four critical locations:

  1. Post() method: Guards SubmitThreadpoolWork() call and reverts thread count increment if work cannot be submitted
  2. AwaitTermination() method: Guards WaitForThreadpoolWorkCallbacks() call to prevent similar crashes
  3. WaitForThreadPoolWorkCompletion() method: Guards against null handles in tracked work loop
  4. TrackThreadPoolWork() method: Prevents tracking of invalid handles

Example of the fix

Before:

void ThreadPoolSchedulerWin::Post() noexcept {
  // ... thread count logic ...
  ::SubmitThreadpoolWork(m_threadPoolWork.get()); // Can crash if null
}

After:

void ThreadPoolSchedulerWin::Post() noexcept {
  // ... thread count logic ...
  if (m_threadPoolWork.get() != nullptr) {
    ::SubmitThreadpoolWork(m_threadPoolWork.get());
  } else {
    --m_usedThreads; // Revert thread count if we can't submit work
  }
}

These changes ensure Windows ThreadPool APIs are never called with invalid parameters while maintaining proper state consistency.

Fixes #15099.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Microsoft Reviewers: Open in CodeFlow

Copilot AI changed the title [WIP] [Paper][0.72][Watson Failure] caused by INVALID_PARAMETER_c000000d_Microsoft.ReactNative.dll!Mso::ThreadPoolSchedulerWin::Post Fix INVALID_PARAMETER crash in ThreadPoolSchedulerWin::Post by adding null pointer guards Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Paper][0.72][Watson Failure] caused by INVALID_PARAMETER_c000000d_Microsoft.ReactNative.dll!Mso::ThreadPoolSchedulerWin::Post

2 participants