Azure / azure-relay-dotnet

☁️ .NET Standard client library for Azure Relay Hybrid Connections

Home Page:https://docs.microsoft.com/en-us/azure/service-bus-relay/relay-what-is-it

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow setting response StatusDescription with null

IonKiwi opened this issue · comments

Actual Behavior

When using Microsoft.Azure.Relay.AspNetCore and calling HttpContext.Response.Clear()
asp.net core wil set the response ReasonPhrase to null and the Microsoft.Azure.Relay.AspNetCore response implementation, in turn sets the Microsoft.Azure.Relay response StatusDescription to null.

The Azure relay implementation of Response.StatusDescription does not allow setting null, resulting in an exception.

Stack / exception when calling Response.Clear()

fail: Microsoft.Azure.Relay.AspNetCore.MessagePump[0]
      ProcessRequestAsync
System.ArgumentNullException: Value cannot be null. (Parameter 'value')
   at Microsoft.Azure.Relay.RelayedHttpListenerResponse.set_StatusDescription(String value)
   at Microsoft.Azure.Relay.AspNetCore.Response.set_ReasonPhrase(String value)
   at Microsoft.Azure.Relay.AspNetCore.FeatureContext.Microsoft.AspNetCore.Http.Features.IHttpResponseFeature.set_ReasonPhrase(String value)
   at Microsoft.AspNetCore.Http.ResponseExtensions.Clear(HttpResponse response)
   at Server.Controllers.TestController.Test2() in C:\dev\RelayNullRef\Server\Controllers\TestController.cs:line 28
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.Azure.Relay.AspNetCore.MessagePump.ProcessRequestAsync(Object requestContextObj)
   at Microsoft.Azure.Relay.AspNetCore.MessagePump.ProcessRequestAsync(Object requestContextObj)
fail: Microsoft.Azure.Relay.AspNetCore.MessagePump[0]
      ProcessRequestAsync
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Microsoft.Azure.Relay.RelayedHttpListenerResponse. TrackingId:3555a5b5-57ba-4de6-ac07-f65f3d65dc10_G5, Address:sb://zaas-poc.servicebus.windows.net/zaas-poc-hybrid/Test/Test2, Timestamp:15-6-2021 08:01:43'.
   at Microsoft.Azure.Relay.RelayedHttpListenerResponse.CheckDisposedOrReadOnly()
   at Microsoft.Azure.Relay.RelayedHttpListenerResponse.ResponseWebHeaderCollection.Clear()
   at Microsoft.Azure.Relay.AspNetCore.Response.UpdateHeaders(String key)
   at Microsoft.Azure.Relay.AspNetCore.Response.<.ctor>b__2_0(String key)
   at Microsoft.Azure.Relay.AspNetCore.HeaderCollection.Clear()
   at Microsoft.Azure.Relay.AspNetCore.MessagePump.ProcessRequestAsync(Object requestContextObj)

Expected Behavior

using Microsoft.Azure.Relay.AspNetCore and calling HttpContext.Response.Clear() will not result in an exception.

Versions

.NET 3.1 asp.net core application
Microsoft.Azure.Relay.AspNetCore 1.3.15173 NuGet package
Microsoft.Azure.Relay 2.0.15596 NuGet package