Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSACancelBlockingCall Exception with Amazon

Tags:

amazon-s3

I have occasional exception when reading / storing objects with Amazon S3 from asp.net application.

Exception says: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall. A blocking operation was interrupted by a call to WSACancelBlockingCall

at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

Any ideas about how I can locate what is reason of this error?

here is my read function:

    public Image GetImage(string fullKey, out string errorMessage)
    {
        errorMessage = null;
        try
        {
            GetObjectResponse response = s3Client.GetObject(new GetObjectRequest()
            {
                BucketName = BucketName,
                Key = fullKey,
                Timeout = ImportTimeout
            });
            return Image.FromStream(response.ResponseStream);
        }
        catch (Exception e)
        {
            errorMessage = e.Message;
            Log.Current.WriteError(e);
        }
        return null;
    }

s3Client is initialised in constructor of this class:

s3Client = AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey);
like image 670
st78 Avatar asked Mar 22 '26 19:03

st78


1 Answers

According to aws documentation it is correct to wrap call to GetObject with using:

http://docs.amazonwebservices.com/sdkfornet/latest/apidocs/html/M_Amazon_S3_AmazonS3_GetObject.htm

This eliminates all exceptions related to GetObject method

like image 182
st78 Avatar answered Mar 24 '26 08:03

st78



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!