Bug 15665 - HttpWebResponse stream ends prematurely instead of throwing an exception
Summary: HttpWebResponse stream ends prematurely instead of throwing an exception
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.0.2.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Martin Baulig
Depends on:
Reported: 2013-10-24 15:57 UTC by Oran Dennison
Modified: 2016-12-16 15:31 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Oran Dennison 2013-10-24 15:57:13 UTC
When reading from a stream returned by HttpWebResponse.GetResponseStream(), the Read() call is returning 0 when there is an error reading from the stream, causing the caller to incorrectly assume the end of the stream was reached successfully.  The correct behavior is to throw an IOException.

This problem also exists for Xamarin.Android.

See this forum post for more details, repro steps, and repro code.
Comment 1 Oran Dennison 2013-10-24 16:00:30 UTC
Bug report for Xamarin.Android here: https://bugzilla.xamarin.com/show_bug.cgi?id=15666
Comment 2 Rolf Bjarne Kvinge [MSFT] 2013-10-29 17:57:07 UTC
I can reproduce this with the test case from the forum post and the 20MB jpg link from bug #15666 comment 2.

Looks like some sort of race condition somewhere, since sometimes I got a proper exception.
Comment 3 Oran Dennison 2013-10-29 21:00:31 UTC
I just discovered another factor today.  If I have two simultaneous downloads, one small and one large being downloaded on different threads, when the small one finishes, the large one ends early ( Read() == 0 ).  This seems to happen 100% consistently.
Comment 4 T.J. Purtell 2013-12-27 12:09:27 UTC
Huh. I have definitely seen image files download incorrectly and I ended up putting a manual check for content length matching afterwards to deal with it.  I guess this is a another issue with httpwebrewuest.
Comment 5 Martin Baulig 2016-11-11 09:32:13 UTC
Closing ancient bugs, please reopen if you're still having this problem.
Comment 6 Manuel de la Peña [MSFT] 2016-12-16 15:31:22 UTC
@Oran and @TJ as @Marting mentioned this is a very old bug and we have not had any information since you reported it, I'm closing it unless you can reproduce it with any recent version of the software.