Skip to content

IIS Application pool Crashed During APP Pool Recycle and apparently Gelf was the culprit #37

@fm-gawdeprasad

Description

@fm-gawdeprasad

We use Graylog to log all the Database calls in our application. We had the IIS App Pool recycle scheduled at 3AM in the morning. During the Recycle, the IIS failed to start with following logs in System Event log

An unhandled exception occurred and the process was terminated. Application ID: /LM/W3SVC/2/ROOT Process ID: 4924 Exception: System.ObjectDisposedException Message: Cannot access a disposed object. Object name: 'System.Net.Sockets.Socket'. StackTrace: at System.Net.Sockets.Socket.EndSendTo(IAsyncResult asyncResult) at System.Net.Sockets.UdpClient.EndSend(IAsyncResult asyncResult) at gelf4net.Appender.GelfUdpAppender.SendCallback(IAsyncResult ar) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.ContextAwareResult.CompleteCallback(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.ContextAwareResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) at System.Net.LazyAsyncResult.InvokeCallback(Object result) at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

An unhandled exception occurred and the process was terminated.

Application ID: /LM/W3SVC/2/ROOT

Process ID: 4924

Exception: System.ObjectDisposedException

Message: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.

StackTrace:    at System.Net.Sockets.Socket.EndSendTo(IAsyncResult asyncResult)
   at System.Net.Sockets.UdpClient.EndSend(IAsyncResult asyncResult)
   at gelf4net.Appender.GelfUdpAppender.SendCallback(IAsyncResult ar)
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.LazyAsyncResult.InvokeCallback(Object result)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

The number of message being sent to Graylog was pretty high as it sent 20lac messages in the span of 17 hours (which is too much). When I looked at GelfUdpAppender, I think what might have happened is the client object was recycled before the EndSend() is called. But I am not sure about it.

Following is how we are creating logger. We created the static instance of the logger

 static readonly ILog log = LogManager.GetLogger(typeof(LogLiveSps));

And I am logging the error as below

log.Error(sb.ToString());

Do let me know if my assumption is correct. With this effort we have memached most of the DB calls, but my worry is that, if I enable graylog again, it should not crash the app pool on live site during recycle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions