Skip to content

Deadlock in raven-logback #151

Closed
Closed

Description

@tootedom

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

  1. jmason commented on Mar 4, 2016

    @jmason

    We just ran into this in production, too. It'd be nice to see it fixed

  2. self-assigned this
    on Mar 18, 2016
  3. bretthoerner commented on Mar 19, 2016

    @bretthoerner

    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

  4. bretthoerner commented on Oct 14, 2016

    @bretthoerner

    I'm hoping this helps: #265

  5. bretthoerner commented on Oct 15, 2016

    @bretthoerner

    The above (filtering out com.getsentry.raven from the SentryAppender) was released as part of 7.8.0 if you'd like to try it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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