-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Fix unbalanced unlock in PtySignalInputThread::_Shutdown #12181
Changes from 4 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 |
---|---|---|
|
@@ -170,7 +170,6 @@ bool PtySignalInputThread::_GetData(_Out_writes_bytes_(cbBuffer) void* const pBu | |
if (lastError == ERROR_BROKEN_PIPE) | ||
{ | ||
_Shutdown(); | ||
return false; | ||
} | ||
else | ||
{ | ||
|
@@ -180,7 +179,6 @@ bool PtySignalInputThread::_GetData(_Out_writes_bytes_(cbBuffer) void* const pBu | |
else if (dwRead != cbBuffer) | ||
{ | ||
_Shutdown(); | ||
return false; | ||
} | ||
|
||
return true; | ||
|
@@ -233,6 +231,7 @@ void PtySignalInputThread::_Shutdown() | |
// happens if this method is called outside of lock, but if we're | ||
// currently locked, we want to make sure ctrl events are handled | ||
// _before_ we RundownAndExit. | ||
LockConsole(); | ||
ProcessCtrlEvents(); | ||
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. Why do we not have to do this anymore? IIRC there's a very bizarre edge case bug that can occur if we don't dispatch ctrl events before tearing down 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 believe this might be a copy-paste mistake... However I've just pushed a change which makes the entire code a lot more robust in general in my opinion. 🙂 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'm definitely worried about making changes here. If it's a copy/paste error, we should make sure we understand when it was introduced and when it became an error. Pull up the team OneNote and use the guidance on importing pre-github history if you need to! :) 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 found the original comments on the PR that added this function (!2698602):
This issue has now been resolved by jiggling in a different way instead. 😅 |
||
|
||
// Make sure we terminate. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -520,5 +520,5 @@ void CloseConsoleProcessState() | |
// ctrl event will never actually get dispatched. | ||
// So, lock and unlock here, to make sure the ctrl event gets handled. | ||
LockConsole(); | ||
auto Unlock = wil::scope_exit([&] { UnlockConsole(); }); | ||
UnlockConsole(); | ||
Comment on lines
522
to
+523
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. @zadjii-msft I've drastically simplified the PR now. In fact if we want to, we can just keep the two added Technically we can remove these two lines from |
||
} |
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.
(okay sorry to nitpick, but all this code is terribly fragile)
why are we removing these
return false
s in_GetData
? Aren't these needed to get the input threads to break out of their while loops?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.
Oh right, cause we'll
ExitProcess
inRundownAndExit
in_Shutdown
, that makes sense.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.
So here's the story behind this change:
Initially I tried to add some code after
ServiceLocator::RundownAndExit(ERROR_BROKEN_PIPE);
. This doesn't make any sense though, asRundownAndExit
never returns, but neither the regular compilation nor the AuditMode marked this as an issue. If we use the[[noreturn]]
annotation however we can turn this programming error into an immediate compilation warning. This is why this PR adds[[noreturn]]
.But now that any such code results in a warning I was forced to remove this "unreachable code".
Do you agree with this change? If not, would you like me to revert it?
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.
no yea no, this makes sense, more sense than before. Defs keep this.