Skip to content

BUG(S3): truncated response followed by TCP FIN leaves toPublisher() subscriber hanging #7465

In review

Description

@superhx

Describe the bug

When using S3AsyncClient with NettyNioAsyncHttpClient and AsyncResponseTransformer.toPublisher(), a response body truncated by a normal TCP close (FIN) can leave the body subscriber waiting indefinitely.

The SDK detects a Content-Length mismatch but does not deliver onError() to the body subscriber. Consequently, application-level failure handling and cleanup that depend on body completion never execute.

Downstream report: AutoMQ/automq#3664

Expected behavior

When the connection closes before the declared response body has been received, the body subscriber should receive onError(Throwable).

This report concerns missing error notification, not automatic retries.

Bug flow

Source inspected: master at commit 0d74c169df9c7f2a2d4d59cdcf7732472d9809e6.

toPublisher() future completes when the body publisher becomes available
  → application subscribes and requests body data
  → server sends fewer bytes than Content-Length, then closes with FIN
  → HandlerPublisher.channelInactive() invokes complete()
  → PublisherAdapter.onComplete() detects the length mismatch
  → IOException is reported to the response handler, but not the subscriber
  → subscriber receives neither onComplete() nor onError()

The key code is in ResponseHandler.PublisherAdapter.onComplete():

try {
    validateResponseContentLength(channelContext);
    // Notify subscriber.onComplete() and finalize the response.
    ...
} catch (IOException e) {
    notifyError(e);
    // Close and release the channel.
    ...
}

The catch block never calls subscriber.onError(e). notifyError() only notifies the HTTP response handler and completes the HTTP execute future exceptionally.

For PublisherAsyncResponseTransformer, that error notification cannot reach the body consumer:

public void onStream(SdkPublisher<ByteBuffer> publisher) {
    future.complete(new ResponsePublisher<>(response, publisher, timeout));
}

public void exceptionOccurred(Throwable error) {
    future.completeExceptionally(error); // Already completed by onStream().
}

By contrast, PublisherAdapter.onError() explicitly calls subscriber.onError(), consistent with the downstream observation that TCP RST and read timeout correctly report errors.

Reproduction steps

  1. Configure a Netty-backed S3AsyncClient to use a local HTTP server.
  2. Issue a ranged getObject() with AsyncResponseTransformer.toPublisher().
  3. Subscribe to the returned publisher and request body data.
  4. Respond with HTTP 206, valid range headers, and Content-Length: N.
  5. Send a non-empty body shorter than N, then close the connection normally with FIN.
  6. Observe that the subscriber receives neither onComplete() nor onError().

Controls reported downstream:

  • TCP RST during body transfer: error notification is received.
  • Connection left idle until Netty read timeout: error notification is received.

Verification status

The downstream reporter observed this behavior with SDK 2.26.10. We inspected master at the commit above and found the missing subscriber error-notification path. We have not independently run the network reproducer on master.

Suggested fix

Deliver content-length validation failures to the body subscriber through onError(), preserving exactly-once terminal signaling and channel cleanup.

Note that PublisherAdapter.onComplete() sets isDone before validation, so simply calling the existing onError() method from the catch block would return without notifying the subscriber.

Environment

Downstream report: Linux / Kubernetes, Netty NIO HTTP client.

Activity

  1. changed the title [-]Netty: truncated response followed by TCP FIN leaves toPublisher() subscriber hanging[/-] [+]S3: truncated response followed by TCP FIN leaves toPublisher() subscriber hanging[/+] on Oct 20, 2026
  2. changed the title [-]S3: truncated response followed by TCP FIN leaves toPublisher() subscriber hanging[/-] [+]BUG(S3): truncated response followed by TCP FIN leaves toPublisher() subscriber hanging[/+] on Oct 20, 2026
  3. debora-ito commented on Oct 20, 2026

    @debora-ito
    Member

    Hi @superhx thank you for reaching out.

    I see you also reported a related issue in #6949, I apologize it didn't get a reply yet, it probably went unnoticed because they don't have the labels that are applied when the Github new issue template is used.

    Anyway, we are taking a look.

  4. added
    bug
    investigating
    on Oct 20, 2026
  5. self-assigned this
    on Oct 20, 2026
  6. added
    p2
    and removed
    investigating
    on Oct 26, 2026
  7. removed their assignment
    on Oct 26, 2026
  8. huong8373tt-beep commented on Oct 30, 2026

    @huong8373tt-beep

    I am preparing a focused fix for the missing terminal onError notification when streamed response content-length validation fails, with a regression test in the Netty publisher adapter path.

    Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

  9. huong8373tt-beep commented on Oct 30, 2026

    @huong8373tt-beep

    Opened #7499 with the focused Netty publisher-adapter fix and regression coverage. Local verification completed with the Netty dependency reactor build and PublisherAdapterTest (5 tests passed).

    Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughttp-client:nettyp2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions