Skip to content

StreamClosed in sendMessage instead of Failure in Initial Metadata #1425

Open
@fabianmuecke

Description

@fabianmuecke

Describe the bug

We make a ClientStreamingCall, to upload a file in chunks to our backends. There are conditions, where the backend will immediately report a failure in the initial metadata and close the stream. If we do not send anything, the backend won't deliver initial metadata, so we have to start sending the chunks.

However there is unexpected behavior in the sequence of events. Instead of the initial metadata stream reporting the failure, the first thing to happen is the sendMessage reporting a stream closed - although obviously the error response of the server happens before the stream is closed.

To reproduce

Steps to reproduce the bug you've found:

  1. Make a ClientStreamingCall
  2. Subscribe to initialMetadata
  3. Start sending messages and make sure they're still being sent, when
  4. The server responds with a failure in initialMetadata and
  5. Closes the stream

Expected behaviour

I expect the server error in initialMetadata to be propagated before the StreamClosed error in sendMessage.

Additional information

I dug deeper and followed the trace back to processStateChange(_ stateChange: NIOHTTP2ConnectionStateChange?) NIOHTTP2Handler. This is called from processFrame(_ frame: HTTP2Frame, flowControlledLength: Int, context: ChannelHandlerContext) in the same class before processPendingUserEvents(context: ChannelHandlerContext) is called. The latter will propagate the server failure, while processStateChange will propagate the StreamClosed in failDroppedPromises.

I couldn't figure out a way to get the errors in the right order and consider this a bug, as the server error happens before the stream is closed, but is propagated after the StreamClosed error. I can't say, if this is a grpc-swift or a swift-nio-http2 bug, as it is just too deep inside, for me to be sure.

We're using:

    {
        "package": "grpc-swift",
        "repositoryURL": "https://github.com/grpc/grpc-swift",
        "state": {
          "branch": null,
          "revision": "593fe0fe931f7e838969243cd137be48e8055b1d",
          "version": "1.7.3"
        }
      },
    ...
     {
        "package": "swift-nio-http2",
        "repositoryURL": "https://github.com/apple/swift-nio-http2.git",
        "state": {
          "branch": null,
          "revision": "50c25c132b140e62b45e90b5a76f13ded02c8a46",
          "version": "1.20.1"
        }
      },

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugFeature doesn't work as expected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions