Skip to content

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Apr 9, 2025

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 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 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.

@Copilot Copilot AI review requested due to automatic review settings April 9, 2025 11:15
@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 9, 2025
Copy link
Contributor

@Copilot 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.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@tommcdon tommcdon added area-VM-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 9, 2025
@tommcdon
Copy link
Member

tommcdon commented Apr 9, 2025

@jkotas @AaronRobinsonMSFT

@Tanya-Solyanik
Copy link

@lateralusX - is this specific to StackOverflow? I see VS debugger hangs on Binder exceptions as well

@lateralusX
Copy link
Member Author

lateralusX commented Apr 10, 2025

@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.
@lateralusX
Copy link
Member Author

Failures are known errors.

@lateralusX lateralusX merged commit 4bfdd53 into dotnet:main Apr 11, 2025
155 of 159 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StackOverFlowException no longer breaks into the debugger on F5, instead the app hangs

6 participants