-
Notifications
You must be signed in to change notification settings - Fork 171
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
Crash when deserializing a HttpResponseMessage on .NET Core #213
Comments
This is the contents of the serialized HttpResponseMessage. It looks normal to me |
Interesting problem. Thanks for reporting. I will have a look and get back to you soon. |
It |
Thanks :) And thanks for the great library |
Re-opening to keep track. The issue currently is here: |
There is some breakthrough (finally) with the issue and it is a bug in the .NET Framework from 2.0 to 2.1. Hopefully fixed soon. Thank you for reporting it. |
Hey, While testing and bugfixing, I encountered a similar issue. It turns out that the Removing this part of the header with I'm gonna report this upstream too. |
@pietervdvn thanks for the tip. Issue seems to be in Expires header and waiting for the resolution from Microsoft. |
NP. I could parse expire headers just fine (although I'm on dotnetcore 2.0). |
Now it is being followed here |
Have a similar problem in Asp.Net Web API project. |
@alibaghernejad do you mind posting this to Microsoft thread? It is a frustrating situation. |
I had a try to do that today but the state of the issue is closed now. |
OK, it is fixed apparently. It will be part of the 3.0 milestone. So let's wait until testing if it is fixed. |
Well even .NET Core 3.0 does not seem to fix it so I have got back to them now :( |
Hi, I'm just hit the same issue in my app on asp.net core 3.1. Thanks. |
The problem is you guys need to go to Microsoft open issue and push them to solve the problem. When I go to them, they say it is a low priority, we do not have enough +1 on it to act quicker. |
Hi @aliostad, I am using version 2.8.2 of this library with asp.net core 3.1 and encountered the same problem almost 1 year later. I went to the issue you posted in corefx repo but that issue was closed. What am I going to do to circumvent this problem? Actually, my project previously were using cachecow 2.8.2 with asp.net core 2.1 and they worked well before. I am migrating my project to asp.net core 3.1 today and encountered this problem. |
It might help for the rest who have a similar issue. I found a way to bypass this Expires header issue, provided that in your case, it is totally ok to ignore that header.
And then you can wrap your original FileStore or memoryStore with: That worked for me. Thanks for the great library! |
I ran into this bug when trying to run our application on .NET 6, so I have tried to open an issue in aspnet/AspNetWebStack#313 to get it fixed there. If anybody else has more information/details feel free to comment on to the issue |
Seems like they issued a fix in 3.2.8 |
I've run into a similar issue when the ETag is not well formed. The Http spec says that the ETag header should be quoted and in my case I have a resource that is returning an ETag without quotes. Putting aside the fact that the server should be returning a well-formed ETag, the root problem here as I see it is that the serialisation and deserialisation are not being done by the same library/code and essentially the deserialisation is less tolerant of malformed headers than the normal code path that creates a HttpResponse from the network stream. When reading from the network stream, the headers are added using "response.Content!.Headers.TryAddWithoutValidation(descriptor, headerValue);", but when deserialised it uses "headers.Add(text, value)". There are likely to be other ways to trigger this failure with other malformed headers too. Ironically, the internal class "InternetMessageFormatHeaderParser" that is doing the deserialisation currently has an overload that takes a parameter in the constructor to "ignoreHeaderValidation", but there is nowhere to set that further up the call chain. I think to fix this, the library needs to take control of the deserialisation rather than delegating to the extension method in the "System.Net.Http.Formatting" library (which I think is legacy anyway?). I'm going to have a look at implementing my own FileStore that uses a new "MessageContentHttpMessageSerializer" that does not depend on the "System.Net.Http.Formatting" library. If I get somewhere I am happy with I'll create a pull request. |
@foresightyj answer worked for me. It was an issue with the cache handler |
Same issue happens in .NET8 ... i am using native-AOT, not clear if it is related. But the |
Thanks @esskar . The solution is really to go shout on Microsoft on why it has taken them 6 years and not yet fixed this. Last time I did it, they said it is on you [me] talking about it. Anyway, the solution is to change the -1 to 0 ion the header. Are you saying this solution does not work?? |
I just did some debuging; in my case, it was the ETag does was unable to deserialize. |
@esskar value of ETag has been described by HTTP Spec. So I would add some code to change it before-hand. Can you share whar is the value of ETag? |
Dude, you are using wrong ETag value blaming CacheCow??
The double-quotes are required. So you just need to use the correct value. If a system sets bad value outside HTTP spec it is not gonna work - after all this is a library for HTTP Caching which is highly dependent on the spec. |
I also ran in to this issue in #293 when trying to cache external resources. But the wrong value is being emitted by someone else so it's impossible to fix it. |
OK, I will look into an alternate serialisation. I cannot give an ETA now but expect this to be done within the next few weeks. |
This how C# keeps the value in the HttpResponse. The upstream server correctly sends |
@esskar, really?? By framework do you mean .NET? That would be a horrible mess if true but I doubt it is the case. Can you please send a reproduction? This is an example of a public resource returning strong ETag: https://developer.mozilla.org/static/media/webview.dc22c0f5614a5ff2d93a.svg |
On .NET Core (I've tested 2.0 and 2.1) calling
DeserializeToResponseAsync
onMessageContentHttpMessageSerializer
will crash with certain http responses. (google.com being one of them)I've tested this on 4.7.1 and the crash does not occur. I'm guessing this may be a framework issue, but I'm not 100% sure.
I've attached a project that reproduces the problem
Exception backtrace
CacheCowCrashRepro.zip
Thanks
The text was updated successfully, but these errors were encountered: