Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fm-gawdeprasad opened this issue Jul 5, 2016 · 6 comments

Comments

@fm-gawdeprasad
Copy link

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.

@jjchiw
Copy link
Owner

jjchiw commented Jul 5, 2016

Hi I think it's very similar to this issue #18

And the exception was triggered because log4net.Config.XmlConfigurator.Configure(); was called every time as explained in this comment #18 (comment)

I'll try to reproduce the exception Recycling the App pool and will let you know if I could reproduce it

@JBJamesBrownJB
Copy link

Did you confirm that was the issue?

@jjchiw
Copy link
Owner

jjchiw commented Jan 9, 2017

Hi!

No I couldn't reproduce it or confirmed it, do you have the same issue?

@JBJamesBrownJB
Copy link

Yes I have an WCF service which seems to crash like this when app pool recycles and we are logging a high frequency.

@jjchiw
Copy link
Owner

jjchiw commented Jan 11, 2017

I can't reproduce it, I created a simple nancy application hosted in iis, and I had various thread pointing to the endpoint and logging the time via http and udp, and in the iis console I go to the application pool and recycle it, and all the messages kept going to graylog and didn't experience any crash....

test-gelf4net.zip

@JBJamesBrownJB
Copy link

So I also had WCF tracing turned on at the time. Maybe this is a contributor. I will also attempt to reproduce in a simpler example than our production system. Thanks for your attempts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants