Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Ignore EPIPE errors on Unix when writing to Console#4221

Merged
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:console_eat_brokenpipe
Oct 29, 2015
Merged

Ignore EPIPE errors on Unix when writing to Console#4221
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:console_eat_brokenpipe

Conversation

@stephentoub
Copy link
Copy Markdown
Member

If you pipe from a managed app to another app that ends (or doesn't exist to begin with), attempting to write to it via Console will throw an exception due to the pipe getting broken.

This commit just changes Console's Write to ignore EPIPE (broken pipe) errors. For now I still have it throw an other failures, but we could choose to add additional ignored errno values to the list, or simply not throw for anything.

Fixes #4219
cc: @mellinoe, @ellismg

If you pipe from a managed app to another app that ends (or doesn't exist to begin with), attempting to write to it via Console will throw an exception due to the pipe getting broken.

This commit just changes Console's Write to ignore EPIPE (broken pipe) errors.  For now I still have it throw an other failures, but we could choose to add additional ignored errno values to the list, or simply not throw for anything.
@ellismg
Copy link
Copy Markdown
Contributor

ellismg commented Oct 29, 2015

Seems reasonable.

@ellismg
Copy link
Copy Markdown
Contributor

ellismg commented Oct 29, 2015

LGTM

@mellinoe
Copy link
Copy Markdown
Contributor

LGTM, thanks for the quick fix

@stephentoub
Copy link
Copy Markdown
Member Author

Thanks, guys.

stephentoub added a commit that referenced this pull request Oct 29, 2015
Ignore EPIPE errors on Unix when writing to Console
@stephentoub stephentoub merged commit c837eb9 into dotnet:master Oct 29, 2015
@stephentoub stephentoub deleted the console_eat_brokenpipe branch October 29, 2015 02:28
stephentoub added a commit to stephentoub/corefx that referenced this pull request Oct 29, 2015
This is another attempt at dotnet#4212, which was then immediately reverted in dotnet#4220 because it broke some internal build stuff due to the APIs being used.

Changes on Windows:
- When an Assert fires and the debugger isn't attached, instead of Environment.FailFast'ing, we throw an exception.
- When an Assert fires, we were previously calling Debug.WriteLine twice; now we only call it once.

Changes on Unix:
- Made the Assert functionality match that of Windows in terms of the APIs being called.
- Changed WriteCore to check Debugger.IsLogging and, if it's true, do a Debugger.Log, just as we do on Windows.  Right now these are nops, but when that changes this will become useful.  The fallback when IsLogging is false remains the same: write to syslog.
- Fixed the WriteToStderr function to ignore errors from Write, as we don't want this function throwing exceptions due to failed attempts to output to stderr, such as if it was piped to another program that ended before this one (as with dotnet#4221).
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…okenpipe

Ignore EPIPE errors on Unix when writing to Console

Commit migrated from dotnet/corefx@c837eb9
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
This is another attempt at dotnet/corefx#4212, which was then immediately reverted in dotnet/corefx#4220 because it broke some internal build stuff due to the APIs being used.

Changes on Windows:
- When an Assert fires and the debugger isn't attached, instead of Environment.FailFast'ing, we throw an exception.
- When an Assert fires, we were previously calling Debug.WriteLine twice; now we only call it once.

Changes on Unix:
- Made the Assert functionality match that of Windows in terms of the APIs being called.
- Changed WriteCore to check Debugger.IsLogging and, if it's true, do a Debugger.Log, just as we do on Windows.  Right now these are nops, but when that changes this will become useful.  The fallback when IsLogging is false remains the same: write to syslog.
- Fixed the WriteToStderr function to ignore errors from Write, as we don't want this function throwing exceptions due to failed attempts to output to stderr, such as if it was piped to another program that ended before this one (as with dotnet/corefx#4221).


Commit migrated from dotnet/corefx@68e46ff
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants