[Mono-list] Network Buffering Behavior on Linux

Andrew J. Barr andrew.james.barr at gmail.com
Wed Jun 30 17:23:45 EDT 2010


I am writing a byte[] buffer to a WebClient using UploadData. I have
attempted a similar scheme using WebRequest and the results are the
same. The file is written in 100k chunks, each 100k segment representing
a discrete HTTP request. The server is supposed to respond with an error
code or an md5 hash of the chunk.

On Mac OS X and Windows using Mono 2.6.4, this works as expected. On
Windows using Microsoft .NET, it also works as expected. However, on
Linux using Mono 2.6.4 (tested Debian sid and openSUSE 11.2), the
UploadData call hangs for a long time before an IOException is thrown
("Write timed out") When using WebRequest it would hang on GetResponse.

The code is like this:

public void Go() {

	const int upload_chunk_size = (100*1024); // 100kb
	Uri u = // url goes here
						
	FileStream s = new FileStream(this.filename, FileMode.Open, 
		FileAccess.Read);
	BinaryReader b = new BinaryReader(s);
			
	WebClient w = new WebClient();
	Console.WriteLine("Writing data to WebClient");
	byte[] buf = b.ReadBytes(upload_chunk_size);

	byte[] response = w.UploadData(u, "POST", buf); // HANGS HERE

	this.position += upload_chunk_size;
	Console.WriteLine("Encoding response");
	string md5 = System.Text.Encoding.UTF8.GetString(response);
	md5_list.Add(md5);		
		
	if(this.position < this.fileLength)
		Go();
	else
		UploadDoneEvent(true);
}

Note that the server error case isn't (yet) handled, but it's irrelevant
to the problem at hand.

If I break on UploadData, I can see that the buffer is populated.

On Windows and OS X, it works as expected, POST-ing 100k chunks until
the server returns a failure code (which, again, I haven't implemented
handling) or the upload finishes. On Windows both the Mono and Microsoft
runtimes behave as expected.

Any clues, or should I file a bug? Thanks.

Andrew Barr




More information about the Mono-list mailing list