Skip to main content
gamedev.net
🔒 Locked

strange socket exception

Started by TwistedPix 8 replies 1k views
Original Post
TwistedPix
TwistedPix
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.
humanapp
humanapp
This may sound like a strange question but are you using NOD32 antivirus? I've heard it doesn't play well with CLR apps using IOCP.
TwistedPix
TwistedPix
No i don't have any anti virus or firewall ( except built in windows firewall "ICF" ).
It seems i must write my program in cpp. :(

anyway thx for your reply.
Antheus
Antheus
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?
TwistedPix
TwistedPix
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.
TwistedPix
TwistedPix
yes, it seems the error happens when i run both programs in the same pc.

Thanks for your help. :)
hplus0603
hplus0603
That exception can be caught. Have you tried just continuing from that point on, and see what happens?
enum Bool { True, False, FileNotFound };
TwistedPix
TwistedPix
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
oliii
oliii
If that's a debug mode, try in release.
Everything is better with Metal.
TwistedPix
TwistedPix
Quote:
Original post by oliii
If that's a debug mode, try in release.


no, nothing changed.

anyway thanks :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.