aws-sdk-go-v2: DynamoDB returns operation error `use of closed network`
Describe the bug
SDK often returns the error below after updated SDK version.
acutal error:
operation error DynamoDB: Query, $tableName: https response error StatusCode: 200, RequestID: 123456, deserialization failed, failed to decode response body, read tcp $src->$dst: use of closed network connection
Expected Behavior
No errors
Current Behavior
operation error DynamoDB: Query, $tableName: https response error StatusCode: 200, RequestID: 123456, deserialization failed, failed to decode response body, read tcp $src->$dst: use of closed network connection
Reproduction Steps
ddb := dynamodb.NewFromConfig(defaultCfg)
result, err := ddb.Query(
ctx,
&dynamodb.QueryInput{
TableName: aws.String(tableName),
ExpressionAttributeNames: expr.Names(),
ExpressionAttributeValues: expr.Values(),
KeyConditionExpression: expr.KeyCondition(),
},
)
Possible Solution
No response
Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
github.com/aws/aws-sdk-go-v2 v1.16.8
github.com/aws/aws-sdk-go-v2/config v1.15.15
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.8
github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.4.14
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.10
github.com/aws/smithy-go v1.12.0
Compiler and Version used
1.19
Operating System and version
Linux
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 33 (10 by maintainers)
Commits related to this issue
- Comment out buildRequest body close Testing out: https://github.com/aws/aws-sdk-go-v2/issues/1825 — committed to drshriveer/smithy-go by drshriveer 3 years ago
- chore(deps): upgrade aws-sdk-go-v2 to v1.36 (#24) ## Pull Request Description ### Summary This PR updates the Go toolchain and several dependencies in the `go.mod` file to their latest versions, pr... — committed to oolio-group/dynago by shidil 2 years ago
We are seeing the same issue as well, can we please resurrect this issue?
We also are having significant developer pain when running tests with Github Actions. Once we reach a critical mass of tests, they begin to fail consistently not intermittently. As others have suggested, we tried forking the repo and commenting out the suggested block of code. I also concluded (as did @isaiahvita) that the commented-out block should not have an impact on this issue. But with nothing else to go off, it was worth a try. And removing removing the block of code did stop failures (at least until we built up another critical mass of tests-- so for a month or so, a beautiful, consistent month).
I spent more time attempting to debug the issue in smithy itself as I had a path to reproduce it 100% of the time and quickly learned that any extra infrastructure I added to help debug (with or without the commented block), tended to “fix” the issue.
To me this seems to indicate there is a real race condition somewhere in the code and that simply adding or subtracting work seems to shuffle load just enough that the is less likely to occur. The fact that the issue only occurs after upgrading to sdk2 should also be a clear sign of this. Alas, I did not have time to continue my investigation and now the error is back.
Please re-open the issue.
As far as the error being returned is concerned - the SDK is behaving correctly by not retrying in this case. As people have noted in this thread and others, we DO NOT retry this class of error (ECONNRESET) because it is not deterministically safe to do so.As for the root case, we have no hand in the networking internals of SDK requests - we defer to the configured HTTP client, which is either the standard library implementation in the default case, or one provided by the user.To those affected by this issue, 2 things–
retrying these errors
You can make the underlying error
net.ErrClosedretryable in your client with the following:This should be safe to do for get-type operations such as
dynamodb.Query.root-causing
As of this writing we have been unable to reproduce this in-house whatsoever. I’m going to ask that anyone affected by this issue implement some basic
net.Conntracing to help grant more visibility into where the underlyingClose()calls are coming from. The followingDialContextimplementation, when provided to a transport, will save the stack trace on aClose()call, and dump it to stdout when aRead()on the underlying conn catches this.If you are affected by this issue and are in a position to do so, please implement this tracing logic in your clients and share any of the stack traces produced from it:
Hi everyone,
Since more and more people are reporting being impacted I have re-opened this issue.
In our previous reproduction attempts we were not able to recreate the reported behavior. The next step is to ask one of the customers here on the thread to provide a minimal github repository with code that can reliably reproduce the behavior (even if it means seeing intermittent errors reliably).
That would give us a little more to go off of.
Thanks again, Ran~
Fixed as of https://github.com/aws/aws-sdk-go-v2/releases/tag/release-2025-01-09
We probably have same problem on SQS DeleteMessage. (Request ID and source IP are masked)
go 1.19.3, aws-sdk-go-v2 v1.17.2
Just leaving a comment here to confirm that this problem still exists with the following versions and a local running dynamodb docker instance in gitlab:
Go v1.20.3 github.com/aws/aws-sdk-go-v2 v1.17.7 github.com/aws/aws-sdk-go-v2/config v1.18.2 github.com/aws/aws-sdk-go-v2/credentials v1.13.2 github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.19 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.2 github.com/aws/smithy-go v1.13.5 amazon/dynamodb-local:1.21.0
A retry strategy cannot always be used to retry this error, due to the same reason you are not adding this as a retryable error on SDK level: e.g. adding an element to a list in dynamodb with an update expression is not idempotent and cannot be retried since we do not know if the request was successful or not.
Currently our BDD test suite failes about ~5% of times in the gitlab pipeline because of this error, which is mildly annoying. If our tests are failing then it’s usually in about the same scenario and steps, so I could assume it could be related to a lifecycle of a connection. Either from client or from local dynamodb perspective.
To me it seems that this is happening when the running system is under heavy load.
you can fork smithy-go with a small fix that outcomments a three-line block to avoid closing the request body too early, just as @psmarcin did, and we are also doing now for our production services now - with no problems at all.
https://github.com/psmarcin/smithy-go https://github.com/cwd-nial/smithy-go
Maybe as @a-h commented, does the issue just happen when connecting to DynamoDB local running in Docker?