-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix error handling for COM initialization failures during thread startup #72353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ public sealed partial class Thread | |
private ManagedThreadId _managedThreadId; | ||
private string? _name; | ||
private StartHelper? _startHelper; | ||
private Exception? _startException; | ||
|
||
// Protects starting the thread and setting its priority | ||
private Lock _lock = new Lock(); | ||
|
@@ -367,9 +368,13 @@ private void StartCore() | |
|
||
if (GetThreadStateBit(ThreadState.Unstarted)) | ||
{ | ||
// Lack of memory is the only expected reason for thread creation failure | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was incorrect assumption. COM initialization can fail with PlatformNotSupportedException on Nano server. |
||
throw new ThreadStartException(new OutOfMemoryException()); | ||
Exception? startException = _startException; | ||
startException = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be |
||
|
||
throw new ThreadStartException(startException ?? new OutOfMemoryException()); | ||
} | ||
|
||
Debug.Assert(_startException == null); | ||
} | ||
} | ||
|
||
|
@@ -384,8 +389,10 @@ private static void StartThread(IntPtr parameter) | |
System.Threading.ManagedThreadId.SetForCurrentThread(thread._managedThreadId); | ||
thread.InitializeComOnNewThread(); | ||
} | ||
catch (OutOfMemoryException) | ||
catch (Exception e) | ||
{ | ||
thread._startException = e; | ||
|
||
#if TARGET_UNIX | ||
// This should go away once OnThreadExit stops using t_currentThread to signal | ||
// shutdown of the thread on Unix. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this != CurrentThread)
path needs to have the same error handling and throw InvalidOperationException as the(this == CurrentThread)
path.