Bug 10233 - Unhandled Exception in Socket.BeginSendFile
Summary: Unhandled Exception in Socket.BeginSendFile
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-02-12 05:40 UTC by Torello Querci
Modified: 2013-03-04 11:13 UTC (History)
3 users (show)

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

Semple test code to get the exception. (1.24 KB, text/x-csharp)
2013-02-12 05:40 UTC, Torello Querci
Proposal patch to solve fhit bug (782 bytes, patch)
2013-02-12 05:41 UTC, Torello Querci
Patch with test case proposal (3.02 KB, patch)
2013-02-23 18:51 UTC, Torello Querci
Patch with test case proposal that respect coding guideline (I hope) (3.02 KB, patch)
2013-02-25 16:33 UTC, Torello Querci

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 GitHub or Developer Community 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 Torello Querci 2013-02-12 05:40:22 UTC
Created attachment 3357 [details]
Semple test code to get the exception.

Socket.BeginSendFile method is broken.
If this method is used you get this exception:

Unhandled Exception:
System.ArgumentException: Invalid IAsyncResult - Datatype:System.Runtime.Remoting.Messaging.AsyncResult
Parameter name: syncResult
  at System.Net.Sockets.Socket.EndSendFile (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
  at test_sendfile.MainClass.FileSendCallback (IAsyncResult ar) [0x00000] in <filename unknown>:0 

I try using git and 3.0.3 mono versions.

In attach sample code to get this exception.
Comment 1 Torello Querci 2013-02-12 05:41:23 UTC
Created attachment 3358 [details]
Proposal patch to solve fhit bug
Comment 2 Andres G. Aragoneses 2013-02-13 12:20:54 UTC
I recommend you two things for this patch to get merged:
1) Merge both things into single patch (the testcase should be transformed into a unit test that is included in the mono test suite).
2) Propose it as a pull request in github.
Comment 3 Torello Querci 2013-02-20 05:11:58 UTC

to produce a testcase I need to have a socket server and a file to send to it.

- how can choose the port for socket server? I try with random port and if get an error try with another one?
- where can I store the file to send with BeginSendFile method in order to be compatible with different platform?

I ask this because not find any guideline about this.
Comment 4 Andres G. Aragoneses 2013-02-20 09:57:37 UTC
To setup a socket server: just check how it's done in other tests in the test suite.

In regards to the file: cannot you inline the data in C# in your test instead of using a file?
Comment 5 Andres G. Aragoneses 2013-02-20 10:43:07 UTC
Oops, disregard my last question, obviously the file is needed given this is related to SendFile API.
Comment 6 Torello Querci 2013-02-23 18:51:51 UTC
Created attachment 3468 [details]
Patch with test case proposal

Test case is added in Socket testing code.
I not know if SocketAsyncTest is a better place where insert the testing code.

About the test I use a timer to know if the lamda is not called and raise and exception.
I not find a way to get the exception in thread pool.
Comment 7 Andres G. Aragoneses 2013-02-24 09:59:02 UTC
Some nitpicks and a question:

- You're not following http://www.mono-project.com/Coding_Guidelines in some parts of the patch (like putting a space before "(".

- The last three lines added to Socket.cs have one more tab char than it should be, I think it would look better if you just align the last line with the return statement, and remove one tab in each of the previous two.

- I'm assuming that you have run your test in MS.NET (not Mono) and it passes, right?

If all of the above addressed, I guess you're ready for sending a pull request in github.
Comment 8 Torello Querci 2013-02-25 16:33:31 UTC
Created attachment 3478 [details]
Patch with test case proposal that respect coding guideline (I hope)

Now I hope to respect the coding GuideLine.

I try the test case in .NET writing a testing console application that use the unit test code. I use Visual Studio 2010 to perform the test.
The test is passed.

Is pull request creation the only way to submit this patch for acceptance?
Comment 9 Andres G. Aragoneses 2013-02-25 16:37:34 UTC
Good work!

> Is pull request creation the only way to submit this patch for acceptance?

Well, you can also try to bug the developers via IRC to get them to include this patch manually. Using a pull-request is simply to be believed less of a burden for them because they can just merge the change with a click.
Comment 10 Torello Querci 2013-03-01 08:36:22 UTC
Pull request submitted.


Best Regards
Comment 11 Miguel de Icaza [MSFT] 2013-03-04 11:13:26 UTC
Patch applied