Skip to content

Conversation

@rcoh
Copy link
Collaborator

@rcoh rcoh commented Dec 5, 2025

Fixes #4435

Previously, codegen would always call try_recv_initial() for event streams, which would block waiting for an initial-request or initial-response message. This caused hangs when operations didn't have modeled initial messages.

Changes:

Runtime (aws-smithy-http & aws-smithy-legacy-http):

  • recv() now filters out initial-request/initial-response messages and stores them in a separate buffer
  • try_recv_initial() checks the buffer first before blocking
  • Initial messages are discarded if never explicitly read
  • Added try_recv_initial_with_preprocessor() to legacy version for SigV4 support

Codegen:

  • Server: Only calls try_recv_initial() when httpBindingResolver.handlesEventStreamInitialRequest() returns true
  • Client: Only calls try_recv_initial_response() when there's a parser for non-event-stream output members

Tests:

  • Added test_no_hang_without_initial_message() to verify operations without modeled initial messages don't hang
  • Added test_waits_for_initial_message_when_modeled() to verify operations with modeled initial messages still block correctly
  • Added wait_for_response_ready() to ManualEventStreamClient for testing connection readiness

Documentation:

  • Updated AGENTS.md with EventStream initial message handling behavior
  • Added conditional mutability pattern to AGENTS.md

Motivation and Context

Description

Testing

Checklist

  • For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "client," "server," or both in the applies_to key.
  • For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "aws-sdk-rust" in the applies_to key.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Fixes #4435

Previously, codegen would always call `try_recv_initial()` for event
streams, which would block waiting for an initial-request or
initial-response message. This caused hangs when operations didn't have
modeled initial messages.

**Changes:**

Runtime (aws-smithy-http & aws-smithy-legacy-http):
- `recv()` now filters out initial-request/initial-response messages
  and stores them in a separate buffer
- `try_recv_initial()` checks the buffer first before blocking
- Initial messages are discarded if never explicitly read
- Added `try_recv_initial_with_preprocessor()` to legacy version for
  SigV4 support

Codegen:
- Server: Only calls `try_recv_initial()` when
  `httpBindingResolver.handlesEventStreamInitialRequest()` returns true
- Client: Only calls `try_recv_initial_response()` when there's a
  parser for non-event-stream output members
- Uses `let mut receiver = receiver` pattern for conditional mutability

Tests:
- Added `test_no_hang_without_initial_message()` to verify operations
  without modeled initial messages don't hang
- Added `test_waits_for_initial_message_when_modeled()` to verify
  operations with modeled initial messages still block correctly
- Added `wait_for_response_ready()` to ManualEventStreamClient for
  testing connection readiness

Documentation:
- Updated AGENTS.md with EventStream initial message handling behavior
- Added conditional mutability pattern to AGENTS.md
@rcoh rcoh requested review from a team as code owners December 5, 2025 20:08
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

A new generated diff is ready to view.

A new doc preview is ready to view.

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.

EventStream Initial Request Response handling can lead to hangs

1 participant