How can I troubleshoot the error "Your socket connection to the server was not read from or written to within the timeout period" from Amazon S3?
Last updated: 2021-01-05
I'm trying to upload files to Amazon Simple Storage Service (Amazon S3) using the AWS Command Line Interface (AWS CLI) or an AWS SDK. However, I'm getting an error. How do I resolve this?
When you use the AWS CLI or AWS SDK to upload files to Amazon S3, you might receive the following error:
Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. (Service: Amazon S3; Status Code: 400; Error Code: RequestTimeout)
When the connection between the client and the Amazon S3 server remains idle for 20 seconds or longer, Amazon S3 closes the connection. This results in the 400 RequestTimeout error. To troubleshoot this error, check the following:
- The number of bytes set in the "Content-Length" header is less than the actual file size.
- Network issues such as high latency, packet loss, and congestion.
The number of bytes set in the "Content-Length" header is less than the actual file size
When you send an HTTP request to Amazon S3, Amazon S3 expects to receive the amount of data specified in the Content-Length header. If the expected amount of data isn't received by S3, and the connection is idle for 20 seconds or longer, then the connection is closed.
Therefore, make sure to verify the file size that's sent to Amazon S3. The file must align with the file size specified in the Content-Length header. Otherwise, you receive a 400 RequestTimeout error.
Network issues like high latency, packet loss, and congestion
If packets are dropped because of a slow or poor network connection, then S3 waits for the expected number of bytes to be received. If the connection is idle for 20 seconds or longer, then S3 closes the connection and returns the 400 RequestTimeout error. To verify whether this is causing the error, perform a packet capture and check for any packet drops.