Skip to content

Globally ignore SIGPIPE on Linux #382

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

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 19, 2021

We receive a SIGPIPE if we write to a pipe that points to a crashed process. This in particular happens if the target of a JSONRPCConnection has crashed and we try to send it a message.
On Darwin, DispatchIO ignores SIGPIPE for the pipes handled by it, but that features is not available on Linux.
Instead, globally ignore SIGPIPE on Linux to prevent us from crashing if the JSONRPCConnection's target crashes.

Fixes rdar://75580936

@ahoppen ahoppen requested a review from benlangmuir March 19, 2021 20:18
@ahoppen
Copy link
Member Author

ahoppen commented Mar 19, 2021

@swift-ci Please test


#if os(Linux) || os(Android)
// This is a lazily initialised global variable that when read for the first time, will ignore SIGPIPE.
private let globallyIgnoredSIGPIPE: Bool = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels overcomplicated. Just put this as a static variable inside JSONRPCConnection and access it from the initializer. We don't need a public API for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My line of thinking was that since this is a global property of the process, it should also be toggled by a global function. And I don’t think this really belongs in JSONRPCConnection either. JSONRCPConnection just requests SIGPIPE to be ignored, it shouldn’t need to worry single dispatch etc.

(also: I just copy-pased this code as-is from swift-nio)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it an internal function at least.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good compromise 👍

We receive a `SIGPIPE` if we write to a pipe that points to a crashed process. This in particular happens if the target of a `JSONRPCConnection` has crashed and we try to send it a message.
On Darwin, `DispatchIO` ignores `SIGPIPE` for the pipes handled by it, but that features is not available on Linux.
Instead, globally ignore `SIGPIPE` on Linux to prevent us from crashing if the `JSONRPCConnection`'s target crashes.

Fixes rdar://75580936
@ahoppen ahoppen force-pushed the pr/disable-sigpipe-linux branch from 09ac9f5 to ee53f85 Compare March 22, 2021 21:40
@ahoppen
Copy link
Member Author

ahoppen commented Mar 22, 2021

Made globallyDisableSigpipe an internal function.

@swift-ci Please test

@ahoppen ahoppen merged commit 9aa970c into swiftlang:main Mar 23, 2021
@ahoppen ahoppen deleted the pr/disable-sigpipe-linux branch March 23, 2021 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants