Skip to content

fix: Suppress spurious "failed to close HTTP response body" SDK warning in test output #229

Closed

Description

@scttfrdmn

Problem

When using StartTestServer in tests, the AWS SDK v2 emits the following warning to stderr for nearly every request:

SDK 2026/03/19 17:15:05 WARN failed to close HTTP response body, this may affect connection reuse

This is noisy and clutters go test -v output. It appears on DynamoDB PutItem, Query, UpdateItem, DeleteItem, and EC2 calls — essentially any operation where the response body is not explicitly drained and closed by the plugin's response writer.

Root cause

The AWS SDK v2 logs this warning when resp.Body.Close() returns an error or when the body is not fully drained before closing, which prevents HTTP keep-alive connection reuse. The Substrate test server likely closes the connection or returns a body that the SDK cannot cleanly drain.

Expected behaviour

No spurious warnings in test output. Either:

  1. Substrate's response writer ensures response bodies are fully readable and cleanly closeable, or
  2. The TestServer suppresses SDK-level logging during tests (e.g. by setting aws.NopLogger on the config returned/used internally)

Reproduction

func TestRepro(t *testing.T) {
    env := substrate.StartTestServer(t)
    cfg, _ := awsconfig.LoadDefaultConfig(context.Background(),
        awsconfig.WithBaseEndpoint(env.URL),
        awsconfig.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test","test","test")),
    )
    ddb := dynamodb.NewFromConfig(cfg)
    // Any PutItem/Query call produces the warning
    ddb.PutItem(context.Background(), &dynamodb.PutItemInput{...})
}

Context

Observed in spore-host/spawn tests after migrating from hand-written mocks to Substrate (related to issue #228).

Activity

  1. added
    type: bug
    and removed on Jul 31, 2026
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

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions