-
Notifications
You must be signed in to change notification settings - Fork 862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException thrown from AmazonS3Client.Begin/EndGetObject if no internet connection #274
Comments
This is an obvious bug in the request handling logic in the 3.5 async client. Thanks for pointing it out. |
… for .NET 3.5 async, when an exception is thrown in the pipeline.
The fix for this issue is available in the latest version of the AWS S3 SDK (version 3.1.3.7). The APM API should now throw the same exception as the synchronous version. |
OK, I tried testing with 3.1.3.8 and this doesn't seem to be working correctly: I tried running the following with no Internet connection: class Program
{
static IAmazonS3 s3Client;
static void GetObjectCallback(IAsyncResult result)
{
Console.WriteLine("{0} GetObjectCallback was triggered", DateTime.UtcNow);
GetObjectResponse response = s3Client.EndGetObject(result);
Console.WriteLine("{0} EndGetObject returned", DateTime.UtcNow);
}
static void Main(string[] args)
{
s3Client = new AmazonS3Client();
GetObjectRequest request = new GetObjectRequest
{
BucketName = "<bucket-name>",
Key = "<key-name>",
};
Console.WriteLine("{0} About to call BeginGetObject", DateTime.UtcNow);
try
{
s3Client.BeginGetObject(request, new AsyncCallback(GetObjectCallback), null);
}
catch (Exception e)
{
Console.WriteLine("{0} BeginGetObject threw {1}", DateTime.UtcNow, e);
}
finally
{
Console.WriteLine("{0} BeginGetObject Elapsed time", DateTime.UtcNow);
}
Console.WriteLine("Hit return to exit");
Console.ReadLine();
}
} Here is the output from my machine:
Is there anyway to use the *Async methods with .NET 4.0 instead? |
Hi, 1 & 3. You need to have a try catch block around the EndGetObject call. In the current code, the EndGetObject throwns an exception as expected, which is not handled by GetObjectCallback method, causing the callback method to be called again. The callback should not be called multiple time by the SDK, this is a bug and we are working on a fix for this. If you catch the appropriate exception in the callback, it won't be called again.
2 . You are correct, the BeginGetObject should not block for the retries, I'll let you know when a fix is available for this. The work around for this may be to reduce the number of retries, the default value for max retries is 4.
You cannot use the *Async methods on .NET 4.0, they are only available .NET 4.5 onward. |
- If the user callback method throws an unhandled exception into the SDK code the user callback is called again. Added code to catch unhandled exception from user callback and log it. - In certain cases (network unplugged), the callback methods in HttpHandler are called on the same thread (synchronously). Added code to detect this case using AsyncResult.CompletedSynchronously, if callback is invoked synchronously, we call the subsequent logic on a background thread.
A fix for this issue is available in version 3.1.3.10 of AWS S3 SDK . This fix catches unhandled exceptions being thrown from the user code in the async callback, and does not block the BeginXyz call under certain conditions when retries are performed. |
Using 3.1.3.5 with .NET 4.0 Client Profile
The following works fine if I have an active internet connection:
However, if I disable my network adapter prior to running the above, a NullReferenceException is thrown out of the SDK with the following stack trace:
In this scenario, I would expect to see a network exception of some type. If I replace the APM code with a synchronous
s3Client.GetObject
call then I do see anAmazonServiceException
with a nestedWebException
.The text was updated successfully, but these errors were encountered: