-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix issue when logging stack overflow in WinForm apps. #114432
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 issue when logging stack overflow in WinForm apps. #114432
Conversation
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.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
@lateralusX - is this specific to StackOverflow? I see VS debugger hangs on Binder exceptions as well |
It will happen to anything that logs through this function, there are some low level errors and low level exceptions that could take that route, so likely related. |
WinForm apps doesn't have a console and apparently, Windows implementation of fileno doesn't have same behaviour as POSIX implementation where a return of -1 means error. On Windows, fileno will return -2 when there is no console attached to the app. This bypass the check in write_file that should have return 0, instead it will call_write that will return an error that was not fully accounted for leading to a infinite loop. Fix makes sure Windows implementation sees -1 and -2 as invalid file descriptors. Fix also account for errors returned by _write breaking out of the loop. Fixes dotnet#114412.
is no real error return, so as long as it gets called with a valid stream, it should return something that write/_write should handle and since we handle error returns from calls to write/_write, in minipal_log_write it might be better to let underlying API's decode the meaning of file descriptors returned by fileno/_fileno. minipal_log_write will only pass stdout/stderr to fileno/_fileno and they should always be valid file streams, even if there is no console attached. On a Windows app running without console, it will return back a file descriptor of -2 in that case that _write will see as a unavailable console and return -1 that minipal_log_write will handle.
bdbe453
to
9ea343f
Compare
Failures are known errors. |
WinForm apps doesn't have a console and apparently, Windows implementation of
fileno
doesn't have same behavior as POSIX implementation where a return of -1 means error. On Windows,fileno
will return -2 when there is no console attached to the app. This bypass the check inwrite_file
that should have return 0, instead it will call_write
that will return an error that was not fully accounted for leading to an infinite loop.Fix makes sure Windows implementation sees -1 and -2 as invalid file descriptors. Fix also account for errors returned by
_write
breaking out of the loop.Fixes #114412.