Skip to content
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

Avoid double-closing on fcntl failures #2409

Merged
merged 1 commit into from
Apr 20, 2023

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Apr 20, 2023

Motivation:

The fix provided in #2407 was subtly wrong. ignoreSIGPIPE, which throws the error in question, closes the FD on error except on EINVAL from fcntl, where it instead does not. This inconsistent behaviour is the source of the bug. Because this behaviour is inconsistent, the fix from PR #2407 is also inconsistent and can in some cases double-close the socket.

The actual issue is not as old as I expected: the code can be observed by reviewing the change in #1598, which incorrectly inserted the error transformation before the call to close.

Modifications:

Result:

More resilient fix.

Motivation:

The fix provided in apple#2407 was subtly wrong. ignoreSIGPIPE, which throws
the error in question, closes the FD on error _except_ on EINVAL from
fcntl, where it instead does not. This inconsistent behaviour is the
source of the bug. Because this behaviour is inconsistent, the fix from
PR apple#2407 is also inconsistent and can in some cases double-close the
socket.

The actual issue is not as old as I expected: the code can be observed
by reviewing the change in apple#1598, which incorrectly inserted the error
transformation before the call to close.

Modifications:

- Revert the change from apple#2407.
- Move the close in ignoreSIGPIPE to before the error check, rather than
  after, so we unconditionally execute it.

Result:

More resilient fix.
@Lukasa Lukasa added the semver/none No version bump required. label Apr 20, 2023
@Lukasa Lukasa merged commit f7c4655 into apple:main Apr 20, 2023
@Lukasa Lukasa deleted the cb-repair-the-close-fix branch April 20, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/none No version bump required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants