I am using AmazonS3Client for storing and accessing images on the website. The problem is when an images is read it opens up a connection which stays in the close_wait state and overtime when all the ports are exhausted it causes the site to become unresponsive and only a restart of the IIS solves the problem temporarily.
Here is the method which is used for reading the images
public Stream Read(string path)
{
path = MapPath(path);
var request = new GetObjectRequest { BucketName = BucketName, Key = path };
using (var response = AmazonClient.GetObject(request))
{
var result = new MemoryStream();
response.ResponseStream.CopyTo(result);
result.Position = 0;
return result;
}
}
How to close the connection after the image is read?