Skip to content

protoc-gen-grpc-swift: FileHandle for stdin, stdout #1361

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
Feb 14, 2022

Conversation

lrewega
Copy link
Contributor

@lrewega lrewega commented Feb 12, 2022

This fixes a case where the output response is silently truncated.
Truncation occurs because the write syscall is only invoked a single
time, but write may return a value indicating a partial write for
various reasons, even in a blocking call. For example, if stdout is a
nonblocking pipe, output is truncated when the pipe is full.

Instead of rewriting Stdout.write to handle this case, let's migrate to
FileHandle for I/O, available as of Swift 3.2. swift-protobuf has
already migrated to FileHandle, see also
github.com/apple/swift-protobuf/commit/2ccad3484e06d180af3bd7be53c96d41e8f03a62

This fixes a case where the output response is silently truncated.
Truncation occurs because the `write` syscall is only invoked a single
time, but `write` may return a value indicating a partial write for
various reasons, even in a blocking call. For example, if stdout is a
nonblocking pipe, output is truncated when the pipe is full.

Instead of rewriting Stdout.write to handle this case, let's migrate to
FileHandle for I/O, available as of Swift 3.2.

swift-protobuf has already migrated, and this commit is mostly a port of
github.com/apple/swift-protobuf/commit/2ccad3484e06d180af3bd7be53c96d41e8f03a62
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 12, 2022

CLA Signed

The committers are authorized under a signed CLA.

Copy link
Collaborator

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Nice fix; thank you!

@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Feb 14, 2022
@glbrntt glbrntt merged commit ff11e2a into grpc:main Feb 14, 2022
bimawa pushed a commit to StreamLayer/grpc-swift that referenced this pull request Jun 17, 2022
This fixes a case where the output response is silently truncated.
Truncation occurs because the `write` syscall is only invoked a single
time, but `write` may return a value indicating a partial write for
various reasons, even in a blocking call. For example, if stdout is a
nonblocking pipe, output is truncated when the pipe is full.

Instead of rewriting Stdout.write to handle this case, let's migrate to
FileHandle for I/O, available as of Swift 3.2.

swift-protobuf has already migrated, and this commit is mostly a port of
github.com/apple/swift-protobuf/commit/2ccad3484e06d180af3bd7be53c96d41e8f03a62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants