Skip to content

Commit

Permalink
Fix for #274 , response handler logic being called instead of skipped…
Browse files Browse the repository at this point in the history
… for .NET 3.5 async, when an exception is thrown in the pipeline.
  • Loading branch information
gokarnm committed Nov 19, 2015
1 parent ff7ef4b commit c68badb
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 15 deletions.
4 changes: 0 additions & 4 deletions sdk/src/Core/Amazon.Runtime/AmazonServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ protected void ProcessRequestHandlers(IExecutionContext executionContext)

protected void ProcessResponseHandlers(IExecutionContext executionContext)
{
//if (request == null)
// return;
if (AfterResponseEvent == null)
return;

Expand All @@ -258,8 +256,6 @@ protected void ProcessResponseHandlers(IExecutionContext executionContext)

protected virtual void ProcessExceptionHandlers(IExecutionContext executionContext, Exception exception)
{
//if (request == null)
// return;
if (ExceptionEvent == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public override IAsyncResult InvokeAsync(IAsyncExecutionContext executionContext
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
// Process the response if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
}
base.InvokeAsyncCallback(executionContext);
}
#endif
Expand Down
13 changes: 9 additions & 4 deletions sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/RedirectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
// Call InvokeAsync to redirect to new location.
if (HandleRedirect(ExecutionContext.CreateFromAsyncContext(executionContext)))
// Check for redirect if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
base.InvokeAsync(executionContext);
return;
// Check if a redirect is required
if (HandleRedirect(ExecutionContext.CreateFromAsyncContext(executionContext)))
{
// Call InvokeAsync to redirect to new location.
base.InvokeAsync(executionContext);
return;
}
}

// Not a redirect, call outer callbacks to continue processing response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
/// <param name="executionContext">The execution context, it contains the
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
{
// Process the response if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
}
base.InvokeAsyncCallback(executionContext);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
// Process the response if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
}
base.InvokeAsyncCallback(executionContext);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
// Process the response if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
}
base.InvokeAsyncCallback(executionContext);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
// Process the response if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
}
base.InvokeAsyncCallback(executionContext);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public override async System.Threading.Tasks.Task<T> InvokeAsync<T>(IExecutionCo
/// request and response context.</param>
protected override void InvokeAsyncCallback(IAsyncExecutionContext executionContext)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
// Process the response if an exception hasn't occured
if (executionContext.ResponseContext.AsyncResult.Exception == null)
{
PostInvoke(ExecutionContext.CreateFromAsyncContext(executionContext));
}
base.InvokeAsyncCallback(executionContext);
}
#endif
Expand Down
21 changes: 21 additions & 0 deletions sdk/test/IntegrationTests/Tests/S3/PutObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ public static void ClassCleanup()
BaseClean();
}

#if AWS_APM_API
[TestMethod]
[TestCategory("S3")]
public void TestAsyncExceptionHandling()
{
GetObjectRequest request = new GetObjectRequest
{
BucketName = "NonExistentBucket",
Key = "NonExistentKey",
};

IAsyncResult result = Client.BeginGetObject(request, null, null);

var exception = AssertExtensions.ExpectException<AmazonS3Exception>(
() => Client.EndGetObject(result));
Assert.AreEqual("NoSuchBucket", exception.ErrorCode);
Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode);
}
#endif


[TestMethod]
[TestCategory("S3")]
public void TestPutAndGetWithInvalidExpires()
Expand Down

0 comments on commit c68badb

Please sign in to comment.