Sign in to follow this  

strange socket exception

This topic is 3834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i'm working on async sockets in c# ( i'm relatively new to this area of .net ). i have strange exception that i couldn't find any solution for it. my problem: basically my program receives data from one client and send that data to other clients, i've no problem with this, the only problem i have is that if i close one client without closing the socket ( which happens when client program terminated abnormally, for example with task manager ) the server program throws an exception with pointing to nowhere. i've also searched the net but i couldn't find any solution. :( exception: An unhandled exception of type 'System.NullReferenceException' occurred in system.dll Additional information: Object reference not set to an instance of an object. callstack: system.dll!System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(uint errorCode = 64, uint numBytes = 0, System.Threading.NativeOverlapped* nativeOverlapped = 1678824) + 0xa0 bytes also i using vs 2003 .net framework 1.1 as i said debugger points to nowhere so i don't have any other clue why this happening :S any help/suggestion is greatly appreciated.

Share this post


Link to post
Share on other sites
Does this happen when running client and server on the same machine?

Or does it happen regardless?

The bug itself makes sense. Overlapped IO is handled by kernel, or at least very low in the system. That part also maintains its own callback thread pool.

If your application shuts down improperly, some of these callbacks will call non-existant memory, and cause exception in the system, not application.

I also suspect that it's not server that crashes, but the overlapped IO for entire system. It makes no sense for one to crash when a completely separate application was shutdown.

Are you sure your code is ok? No funny pointer hacks, no bypassing memory management, no dangling unsafe references, no non-C# API or similar hacks? Even innocent ones?

If so, is there anything you can do to catch exceptions better? I know this is thrown by the OS, but are there any exceptions you're missing, not checking for nulls, or similar?

Share this post


Link to post
Share on other sites
yes i run both programs in one pc (loop back ip), i don't tested it on separate machines yet.

The code itself is very simple and it doesn't involved any unmanaged code or pointer tweaks.

if i close client program normally nothing happens but that problem happen when i f.e comment out the socket closing methods of the client.

also if you want i can provide the server source code.

I'll check the program in separate pcs and let you know the results.

Thanks.

Share this post


Link to post
Share on other sites
Hi
no, the problem still exist in two pc after several test. :(

@ hplus0603:

the compiler only can show disassembly for the error location but i don't have any il experience and if i click continue button it'll work fine just like before. :S

Share this post


Link to post
Share on other sites

This topic is 3834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this