Application (VB.Net) gets crashed due to Microsoft.NET\Framework\v4.0.30319\clr.dll. after try calling TcpClient.Connect(IP) API for 1000 times

0

I face this issue for a while and don't have a good idea how to resolve it.

The application is actually a DLL coded in VB.NET 2013 compiled with .NET framework 4.6.1 in used to do message exchange via TCP port.

The DLL is loaded and running in Win2012R2 with .NET framework 4.5 . DLL is running well without issue when TCP port is connecting.

However, the DLL gets crashed after retrying to open TCP port for a while (in the log file I logged, the retry count reached 1000+ times).

I try to look for the root cause and I found the clr.dll is the main reason causing crash. In other articles I found some information but seems not quite similar to mine...

Below is the windows event log for your reference. I wonder if anyone has faced this issue and resolved it please kind let me know.

Log Name: Application
Source: Application Error
Date: 4/5/2018 2:23:48 AM
Event ID: 1000
Task Category: (100)
Level: Error
Keywords: Classic
User: N/A
Computer: Server11
Description:
Faulting application name: MyProgram.exe, version: 7.8.0.30, time stamp: 0x5984af0d
Faulting module name: clr.dll, version: 4.7.2053.0, time stamp: 0x58fa6bb3
Exception code: 0xc00000fd
Fault offset: 0x0045138d
Faulting process id: 0x1e04
Faulting application start time: 0x01d3cc2fb84774be
Faulting application path: MyProgram.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Report Id: ef43e05d-382c-11e8-80bf-000c291e7679
Faulting package full name:
Faulting package-relative application ID:

c#
.net
vb.net
asked on Stack Overflow Apr 12, 2018 by Jim Yu • edited Apr 12, 2018 by mnille

1 Answer

2

From the looks of it, the exception code 0xc00000fd is a StackOverflow Exception.

This maybe because of recursion or many other issues. however my money is on recursion.

Since its likely a StackOverflow Expception i think you will need to debug the process to catch it properly.

Starting with 2.0 a StackOverflow Exception can only be caught in the following circumstances.

  • The CLR is being run in a hosted environment where the host specifically allows for StackOverflow exceptions to be handled
  • The stackoverflow exception is thrown by user code and not due to an actual stack overflow situation (Reference)

Source C# catch a stack overflow exception

This is also worth reading When can you catch a StackOverflowException?

In short, i doubt this is a bug with .net its self and most likely due to what you are doing (or someone else), since you haven't shown the code all we can assume is you/they are doing something wrong.

Some good practices are

  • Don't use recursion to do any thing silly when connection fails.
  • Make sure you are always disposing and cleaning up your TcpClient or using a using statement
  • If you are trying to do things simultaneously with TcpClient, make sure you are not using Parallel.For/ForEach or anything that is not suitable for IO Bound operations, instead use the async/await pattern (although this is probably not the problem, its good advice).
  • Don't blindly use other peoples libraries

Good luck

answered on Stack Overflow Apr 12, 2018 by TheGeneral

User contributions licensed under CC BY-SA 3.0