ToOptimizedResultUsingCache gives a bad response

Using ToOptimizedResultUsingCache for a method that returns a view (or some data) will only give a correct response once. Consecutive requests to the same endpoint will give an empty response.

Test project demonstrating the isue can be found here:

Steps to reproduce:

  • Start the porject using the GATH build setting. This will start a console app listening on port 5000.
  • Navigate to http://localhost:5000/test
  • DefaultRequest will be handled and display some html (I omitted the CSS for brevity)
  • Wait until the page is loaded and just refresh

You will see this in the output in VS:

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5000/test  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 22.8383ms 304 text/html
Microsoft.AspNetCore.Server.Kestrel:Information: Connection id "0HL0CHUV4QNAB" communication error

Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4081 ECANCELED operation canceled

This is not as expected. It seems to be related to ServiceStack sending Header data after Kestrel already sent some data to the client.
As soon as the cache time elapses/expires, it will return a correct response again (just once)

@mythz should I check out the sourcecode and try to fix this, or is this too deep down?

I suspect the error is happening due to the fact that the reply does not fit into 1 TCP block (which could be sent directly as a result of the request). This html file is bigger (about 35 kbytes) and results in a 6 kb chunk being sent. Just an idea…

I’ve already resolved this issue but I’m investigating at how best to handle Error Responses in Razor Views since MVC RazorFormat doesn’t let you populate an ErrorResponse model when it expects a different model type.

That sounds like it’s going to be a breaking change… Sorry I found this…

Just redeployed .NET Core packages, this issue should now be resolved from v1.0.30 of .Core packages on NuGet.

Perfect. Works like a charm. The only issue I am facing now it bandwidth issues. 10k request is no longer possible, so I need to upgrade to a bigger connection :smile:
CPU remains at a low level, so that is good.

1 Like