RequestLogsFeature with CacheResponse attribute

Hello!

If I use the CacheResponse attribute the cached response logging is crashing with a System.ObjectDisposedException exception.

Exception thrown: 'System.ObjectDisposedException' in System.dll ("Cannot access a disposed object.").

Here is the relevant call stack:

System.dll!System.Net.HttpListenerRequest.CheckDisposed()
System.dll!System.Net.HttpListenerRequest.GetKnownHeader(System.Net.HttpRequestHeader header = {unknown})
System.dll!System.Net.HttpListenerRequest.ContentType.get()
ServiceStack.dll!ServiceStack.Host.HttpListener.ListenerRequest.ContentType.get()
ServiceStack.dll!ServiceStack.Host.HttpListener.ListenerRequest.IsContentType(string ct = {unknown}, bool starts_with = {unknown})
ServiceStack.dll!ServiceStack.Host.HttpListener.ListenerRequest.Form.get()
ServiceStack.dll!ServiceStack.Host.HttpListener.ListenerRequest.FormData.get()
ServiceStack.dll!ServiceStack.Host.InMemoryRollingRequestLogger.CreateEntry(ServiceStack.Web.IRequest request = {unknown}, object requestDto = {unknown}, object response = {unknown}, System.TimeSpan requestDuration = {unknown}, System.Type requestType = {unknown})
ServiceStack.dll!ServiceStack.Host.InMemoryRollingRequestLogger.Log(ServiceStack.Web.IRequest request = {unknown}, object requestDto = {unknown}, object response = {unknown}, System.TimeSpan requestDuration = {unknown})	

Tom

I can’t repro this just using an empty [CacheResponse] attribute and the default plugin registration, e.g:

Plugins.Add(new RequestLogsFeature());

Can you post a Service implementation (i.e. that contains the [CacheResponse] attribute) where this fails as well as your RequestLogsFeature plugin registration if it’s different to the above.

Hello!

Sorry for my late reply. I attached a sample project and a screenshot. The second request throw the ObjectDisposedException.

CacheResponseTest

Tom

The issue was using HandleValidCache() short-circuits and closes the Response with the Exception happening when trying to access properties off the disposed Request which is now being guarded against in this commit.

This change is available from v4.5.5 that’s now available on MyGet.