Repository navigation
Description
Hi there,
I thought I would open this as a separate ticket for capturing the deadlock that can occur when using the raven-logback (we commented on: #139, but I think the problem needs a issue of it's own)
During integration we hit an edge case that has been causing a deadlock in logback, and as a result deadlocking our application.
The SentryAppender calls the EventBuilder and also Raven.send. The EventBuilder obtains the hostname from the HostNameCache. The HostnameCache is logging events at debug and also warn (in case of exception). If Raven.send throws an exception, an error is logged.
One of the committers on Logback alludes to the issue of logging during an appender in this ticket (http://jira.qos.ch/browse/LOGBACK-648):
"The bug is an illustration of deadlocks occurring when a logback component, during the process of logging, invokes a service which does logging itself. "
The problem is exactly as described above. That during the process of logging the SentryAppender is calling EventBuilder and Raven.send, that are doing logging themselves.
I believe the way for logging within an Appender is via the AppenderBase's AddError/AddStatus methods. However, those aren't available from within subsequent classes/method calls (EventBuilder/Raven).
One way around this entire deadlocking issue is to NOT send log message originating from net.kencochrame.raven package to the SentryAppender. For example you only target exceptions from your application, to go to the Sentry Appender. Exceptions from Sentry don't (and just go to STDOUT/CONSOLE or FILE), for example:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="Sentry" class="net.kencochrane.raven.logback.SentryAppender">
<dsn>https://publicKey:secretKey@host:port/1?options</dsn>
<tags>tag1:value1,tag2:value2</tags>
<!-- Optional, allows to select the ravenFactory -->
<!--<ravenFactory>net.kencochrane.raven.DefaultRavenFactory</ravenFactory>-->
</appender>
<logger name="only.my.app.packages">
<appender-ref ref="Sentry" />
</logger>
<root level="warn">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
If the services invoked by the SentryAppender (i.e. EventBuilder and Raven), cannot be changed to not log, perhaps the documentation could be updated to reflect the above in order to avoid an application being dead locked.
We are also discussing this issue here: tradier/dropwizard-raven#5
Our applications use drop wizard, which unfortunately does not allow you to target appenders by package. As a result we currently need to implement a filter to drop them.
thanks
/dom
P.S.
The other query we had was related to SentryAppender extending AppenderBase, where perhaps it could extend UnsynchronizedAppenderBase, which removes one element of synchronisation (this does not fix the issue by the way. We were curious as to why SentryAppender is Synchronous).
Activity
jmason commentedon Mar 4, 2016
We just ran into this in production, too. It'd be nice to see it fixed
bretthoerner commentedon Mar 19, 2016
Is anyone able to recreate this locally with an example project?
I went through with a debugger but this block prevents the issue for me: https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java#L62-L65
bretthoerner commentedon Oct 14, 2016
I'm hoping this helps: #265
bretthoerner commentedon Oct 15, 2016
The above (filtering out
com.getsentry.ravenfrom theSentryAppender) was released as part of7.8.0if you'd like to try it out.dont apply current threads to cached events (#151)