-
Notifications
You must be signed in to change notification settings - Fork 2.1k
JsonResult returning partial data to HttpClient #4257
Comments
Hi, |
Thanks for the repro, I was able to reproduce it with latests bits. @Tratcher the code works on a web browser properly but fails when running under TestHost, do you have any idea of what can cause this? (I'm investigating it but any pointer will be appreciated) |
No, that's pretty strange. |
Is there an exception thrown? |
Not that I know of, the tests reports that 79 elements were found instead of 1000, which is the strange thing, I'm trying to build against source to get more insights on it |
@javiercn That's exactly what happens to me. I'm not sure if it can be useful, but if you change the controller to return a list of shorter strings (ex: "0123" instead of "0123456789"), the number of returned elements increases. It seems that for some unknown reason it's trying to keep the size of the resulting JSON around 1Kb. But take my observations with care, I don't want to mislead you. Maybe it's just unrelated. |
This issue is a combination of two problems causing a bigger error. The issue on MVC is that we were registering the returned objects from Json, Ok, etc as disposables, which we don't want to do. The following issue #4509 tracks the behavior change there. The issue in test server was the on response completed event being fired before the response actually completed. The issue tracking that is aspnet/Hosting#721 What is happening is that we register the IEnumerable returned by the action on the list of disposable elements of the response. Then we perform the first write of data to response and the server incorrectly triggers the on response completed event, causing the enumerable to be disposed and the enumeration to stop, after that, we continue writing the rest of the response (at that point we stopped the enumeration early as the enumerable got disposed) and we get the incorrect number of elements. |
Both fixes have been checked-in. This will be fixed for RC2 so I'm closing this issue as there's nothing else to do here. |
Hi,
I'm trying to understand a problem with a simple controller returning an IEnumerable and getting the result with HttpClient. I get a well formed Json response, but it contains only a part of the collection. If I materialize the collection with a ".ToList", then the entire content is returned.
This is the controller:
And this is the test code:
The test fails because it receives only 79 results instead of 1000. Notice that the "fetchedData" string is well formed (i.e. not truncated) and a valid Json array, but with only 79 elements in.
But if on the controller I materialize the list, the controller returns all data:
The only clue I have is that the response is always more or less 1000 bytes. If as an example I reduce the size of the array elements, more elements are returned.
The text was updated successfully, but these errors were encountered: