Would appreciate any kind of help here.
A brief description about scenario -
There is a COM+ running on server (written in C#). The task of this COM is to take a file name, page number of a multi-paged tiff file and the resolution to convert it to a gif file image. This COM is called from a web application using a proxy. The web site gets the converted image and displays in the requested resolution. For printing - it makes 2 request - 1st for display resolution, 2nd in full resolution (which gets printed using window.print()).
Problem -
After sometime server goes out of memory and images are not getting displayed on web site. Server needs to be restarted periodically.
Error
EventType clr20r3, P1 imageCOM.exe, P2 1.0.0.0, P3 4fd65854, P4 prod.web.imaging, P5 1.0.0.0, P6 4fd65853, P7 1a, P8 21, P9 system.outofmemoryexception, P10 NIL.
Here is the error(s) on the web server (these continuously appear every minute) ….
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
I do not have access to production server, but error sent by sysadmin states OutOfMemory.
Thus, assuming memory leak and focusing on it - my findings so far with limited experience of handling this kind of situation -
- Perfmon - I see that Process/Private Bytes are increasing and so is .Net CLR memory/# of bytes in Heap. Thus, I assume it's Managed memory leak. I am not sure though.
- CPU Usage - started with 8% and went up to 80% only at beginning. It dropped back and stayed between 3% - 12%, except couple of times when it went back to 75%-85%. Not sure what is going on here.
I started to debug server COM to have a look at heap, gcroot etc.
- There are 2 objects for count is increasing in the heap with every request made. 1 object is that hold the image data. 2nd object is the event handler to remove the Object 1 (image) from cache when it expires after a certain time.
- Looking at the method call - both objects lead to the same method.
- Code Implementation wise - Requested images are getting cached (up to a certain number) - I can understand it is for better performance. Probably, this is why reference to objects are increasing in heap as mentioned in bullet 1.
I know I gave very vague description, but I need some kind of lead to detect the real issue on server.
EDIT: Image object has been disposed like
Bitmap retVal;
using (MemoryStream buffer = new MemoryStream(doc.FileData, 0, doc.DocumentSize, false, false))
{
using (Bitmap original = new Bitmap(buffer))
{
//select the page to convert and
//perform scaling - full resolution or the requested resolution.
}
}
using (MemoryStream buffer = new MemoryStream())
{
retVal.Save(buffer, ImageFormat.Gif);
retVal.Dispose();
return buffer.GetBuffer();
}