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

Synthesise status when stream closes unexpectedly #1953

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

gjcairo
Copy link
Collaborator

@gjcairo gjcairo commented Jun 28, 2024

Motivation

When the stream closes unexpectedly (the H2 stream channel becomes inactive, an error is fired through the pipeline, or we receive a RST_STREAM frame), the client-side inbound sequence either finishes or throws an error.
To make it easier for higher layers to retry, we want to synthesise a Status instead.

Modifications

  • On the client side, write a Status when one of the aforementioned unexpected closures happens.
  • On the server side, make sure we're always firing an error when closing unexpectedly.
  • On both, make sure we transition the stream state machine to closed.

Result

Inbound sequence now returns a Status instead of finishing/throwing

@gjcairo gjcairo requested a review from glbrntt June 28, 2024 13:37
Sources/GRPCHTTP2Core/Client/GRPCClientStreamHandler.swift Outdated Show resolved Hide resolved
Sources/GRPCHTTP2Core/Client/GRPCClientStreamHandler.swift Outdated Show resolved Hide resolved
Sources/GRPCHTTP2Core/Client/GRPCClientStreamHandler.swift Outdated Show resolved Hide resolved
Comment on lines 1525 to 1527
private func getServerUnexpectedInboundCloseAction(
for reason: UnexpectedInboundCloseReason
) -> OnUnexpectedInboundClose {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason this shouldn't be an init on OnUnexpectedInboundClose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I ended up doing this here because we're using this on the server side only (whereas the type itself is also used on the client side logic). But that's probably a not good enough reason, so I can move it.

Sources/GRPCHTTP2Core/GRPCStreamStateMachine.swift Outdated Show resolved Hide resolved
Sources/GRPCHTTP2Core/GRPCStreamStateMachine.swift Outdated Show resolved Hide resolved
import XCTest

@testable import GRPCHTTP2Core
@testable import NIOHTTP2
Copy link
Collaborator

Choose a reason for hiding this comment

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

We really shouldn't do this because we're taking a dependency on the internal API of a module we don't own.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm yes true - we should probably make the constructor public on NIO though, otherwise this API is unusable.

Sources/GRPCHTTP2Core/Server/GRPCServerStreamHandler.swift Outdated Show resolved Hide resolved
Comment on lines 198 to 199
case .doNothing:
context.fireErrorCaught(error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, is doNothing the right name here? It's a bit confusing that do nothing fires an error here.

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.

Couple of nits re: duplication but otherwise looks great

@gjcairo gjcairo requested a review from glbrntt July 3, 2024 13:55
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.

Fab, thanks Gus

@glbrntt glbrntt merged commit b15469e into grpc:main Jul 3, 2024
17 checks passed
@glbrntt glbrntt added the v2 A change for v2 label Jul 3, 2024
@gjcairo gjcairo deleted the synthetize-status branch July 3, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2 A change for v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants