Tag Archives: S3

Timeout errors in S3 connections using ThreeSharp

I had a bit of trouble using the ThreeSharp libraries to query S3, and I thought I’d share my experiences in case it was useful to anyone. I had a rather bizarre situation that the first 10 requests were always succeeding, and the 11th request was reliably timing out. It turned out to be due to the fact that ThreeSharp doesn’t close the HTTP request stream for you, unless you read the response data stream.

I was ignoring the response data stream for two reasons: Firstly, for an object copy request it doesn’t matter what the response is, provided the request is successful (and the HTTP status ought to be enough to assure that). Secondly, attempting to stream the response via StreamResponseToBytes() or one of the other methods actually causes an exception due to lack of necessary fields being set on the object.

It turned out that a sufficient (if slightly messy) solution is simply to explicitly close the DataStream:

ObjectCopyRequest copyRequest = new ObjectCopyRequest(sourceBucket, key, targetBucket, key);
ObjectCopyResponse copyResponse = query.ObjectCopy(copyRequest);
copyResponse.DataStream.Close();