You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're having a similar issue when using Logback except handily Logback doesn't tell us it's recursing.
The problem is with the code in the EventBuilder on line 556 or line 562.
Basically, when the hostname hasn't yet been set, the EventBuilder (called by SentryAppender) tries to update its hostname cache. This will always log a message (either DEBUG or WARN depending on the outcome of the get hostname call) which is therefore a recursive call. We're hitting this issue in Logback and it's a really big problem when the AsyncAppender's BlockingQueue is full (i.e. we're logging lots of stuff) because it locks our app completely. We can hit it pretty reliably if we turn the hostname cache time down to e.g. 100ms and cause our application to log frequently.
We've discussed several solutions to this, none of which are particularly great. The easiest is to remove the lines linked above and never log from the EventBuilder when it's called from the SentryAppender.
Here's an example stack trace of a locked thread encountering this issue:
"AsyncAppender-Worker-Thread-2" #12 daemon prio=5 os_prio=31 tid=0x00007f9a3aaaf800 nid=0x5d03 waiting on condition [0x0000000124c5d000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006c000ea00> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.ArrayBlockingQueue.put(ArrayBlockingQueue.java:353)
at ch.qos.logback.core.AsyncAppenderBase.put(AsyncAppenderBase.java:139)
at ch.qos.logback.core.AsyncAppenderBase.append(AsyncAppenderBase.java:130)
at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:88)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:273)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:260)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:442)
at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:433)
at ch.qos.logback.classic.Logger.warn(Logger.java:721)
at net.kencochrane.raven.event.EventBuilder$HostnameCache.updateCache(EventBuilder.java:564)
at net.kencochrane.raven.event.EventBuilder$HostnameCache.getHostname(EventBuilder.java:543)
at net.kencochrane.raven.event.EventBuilder.autoSetMissingValues(EventBuilder.java:87)
at net.kencochrane.raven.event.EventBuilder.build(EventBuilder.java:297)
- locked <0x00000007811fca90> (a net.kencochrane.raven.event.EventBuilder)
at net.kencochrane.raven.logback.SentryAppender.buildEvent(SentryAppender.java:207)
at net.kencochrane.raven.logback.SentryAppender.append(SentryAppender.java:132)
at net.kencochrane.raven.logback.SentryAppender.append(SentryAppender.java:26)
at ch.qos.logback.core.AppenderBase.doAppend(AppenderBase.java:85)
- locked <0x00000006c000e130> (a net.kencochrane.raven.logback.SentryAppender)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at ch.qos.logback.core.AsyncAppenderBase$Worker.run(AsyncAppenderBase.java:226)
Note that if we change the SentryAppender to extend UnsynchronizedAppenderBase instead of AppenderBase (we thought that might fix the issue, sadly not) then we get the following stack trace which clearly shows two calls to UnsynchronizedAppenderBase.java:88:
"AsyncAppender-Worker-Thread-2" #12 daemon prio=5 os_prio=31 tid=0x00007fb2be87b000 nid=0x5d03 waiting on condition [0x000000012039a000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006c019c408> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.ArrayBlockingQueue.put(ArrayBlockingQueue.java:353)
at ch.qos.logback.core.AsyncAppenderBase.put(AsyncAppenderBase.java:139)
at ch.qos.logback.core.AsyncAppenderBase.append(AsyncAppenderBase.java:130)
at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:88)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:273)
at ch.qos.logback.classic.Logger.callAppenders(Logger.java:260)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:442)
at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:433)
at ch.qos.logback.classic.Logger.warn(Logger.java:721)
at net.kencochrane.raven.event.EventBuilder$HostnameCache.updateCache(EventBuilder.java:562)
at net.kencochrane.raven.event.EventBuilder$HostnameCache.getHostname(EventBuilder.java:543)
at net.kencochrane.raven.event.EventBuilder.autoSetMissingValues(EventBuilder.java:87)
at net.kencochrane.raven.event.EventBuilder.build(EventBuilder.java:297)
- locked <0x00000007767df740> (a net.kencochrane.raven.event.EventBuilder)
at net.kencochrane.raven.logback.SentryAppender.buildEvent(SentryAppender.java:207)
at net.kencochrane.raven.logback.SentryAppender.append(SentryAppender.java:132)
at net.kencochrane.raven.logback.SentryAppender.append(SentryAppender.java:26)
at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:88)
at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at ch.qos.logback.core.AsyncAppenderBase$Worker.run(AsyncAppenderBase.java:226)
It looks like in Logback world, if you're logging from within an appender you have to call one of the addStatus methods like in this example, the line:
addError("No encoder set for the appender named ["+ name +"].");
Unfortunately as the DEBUG and WARN calls are in the Raven code and aren't Logback specific we can't create a generic solution to this.
TL;DR This deadlocks our app when using Logback (which we're stuck with due to it being a dependency of DropWizard) and could be a very big issue. We think you should remove line 556 and line 562 of EventBuilder.
After further investigation, we discovered more calls to the logger, not just on lines 556 and 562 of EventBuilder. As such, we've implemented a filter so that any events from net.kencochrane.raven don't ever get sent to the SentryAppender, see tradier/dropwizard-raven#5
@bretthoerner this did not fix the issue, stepping through the code I think I see the problem, on the first log event, the SentryAppender initialises raven using the DefaultRavenFactory but during initialisation it will attempt to log info here causing the recursive call.
Maybe the reason you don't see it is because you have no <dsn> in your log4j config and so it does not enter any of the if conditions
I set my DSN externally with an environment variable, and am using an https connection, so that is weird. I see what you mean though (even though I can't seem to reproduce it).
For the life of me I can't reproduce this with log4j2 2.6.1. Logging set to all or info, DSN set to HTTP (I see Sentry INFO logging about the connection too). What is your slf4j version?
slf4j.version=1.7.21. I wonder if its the sequence of events, if you step though it, is the first log event from com.getsentry.raven.DefaultRavenFactory.createConnection() or your applications first log event? Mine is from the app. Another thing to check is whether anything in org.apache.logging.log4j.core.config.AppenderControl.shouldSkip() prevents the recursive call.
I tried chasing this down again to no avail. It's interesting that a user above fixed this in an older version by filtering out all Sentry logs from Sentry itself, which we do now for all logging frameworks.
I've realized that our documentation and example logging configurations were pretty poor, because I don't understand why you'd actually want to set the Sentry appender to anything below WARN. Our example apparently told people to configure Sentry at ALL which is just a bad idea all around. But, most of all, I can't seem to reproduce this at all.
That said, I'm going to improve the docs/examples so that Sentry is filtered to WARN and above -- and if this is an actual production issue for anyone I'd be curious on the details or an example mini project I can use to repro.
Activity
suhyunjeon commentedon Jul 7, 2015
@frecar Did you solve the problem? I have same problem.
tootedom commentedon Sep 15, 2015
We're having a similar issue when using Logback except handily Logback doesn't tell us it's recursing.
The problem is with the code in the EventBuilder on line 556 or line 562.
Basically, when the hostname hasn't yet been set, the EventBuilder (called by SentryAppender) tries to update its hostname cache. This will always log a message (either DEBUG or WARN depending on the outcome of the get hostname call) which is therefore a recursive call. We're hitting this issue in Logback and it's a really big problem when the AsyncAppender's BlockingQueue is full (i.e. we're logging lots of stuff) because it locks our app completely. We can hit it pretty reliably if we turn the hostname cache time down to e.g. 100ms and cause our application to log frequently.
We've discussed several solutions to this, none of which are particularly great. The easiest is to remove the lines linked above and never log from the EventBuilder when it's called from the SentryAppender.
Here's an example stack trace of a locked thread encountering this issue:
Note that if we change the SentryAppender to extend UnsynchronizedAppenderBase instead of AppenderBase (we thought that might fix the issue, sadly not) then we get the following stack trace which clearly shows two calls to UnsynchronizedAppenderBase.java:88:
It looks like in Logback world, if you're logging from within an appender you have to call one of the
addStatusmethods like in this example, the line:Unfortunately as the DEBUG and WARN calls are in the Raven code and aren't Logback specific we can't create a generic solution to this.
TL;DR This deadlocks our app when using Logback (which we're stuck with due to it being a dependency of DropWizard) and could be a very big issue. We think you should remove line 556 and line 562 of EventBuilder.
tootedom commentedon Sep 16, 2015
After further investigation, we discovered more calls to the logger, not just on lines 556 and 562 of EventBuilder. As such, we've implemented a filter so that any events from
net.kencochrane.ravendon't ever get sent to the SentryAppender, see tradier/dropwizard-raven#5loucasa commentedon Oct 5, 2016
I have the same problem, it seems to happen when the sentry appender receives info events, i.e. I don't get the error when I have:
<appenderref ref="Sentry" level="warn"/>bretthoerner commentedon Oct 7, 2016
@loucasa Which logging implementation are you using?
loucasa commentedon Oct 11, 2016
Same, log4j2
bretthoerner commentedon Oct 13, 2016
What version of Raven? I'm trying to recreate the issue with the latest version but I'm having no luck.
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.loucasa commentedon Oct 17, 2016
@bretthoerner this did not fix the issue, stepping through the code I think I see the problem, on the first log event, the SentryAppender initialises raven using the DefaultRavenFactory but during initialisation it will attempt to log info here causing the recursive call.
Maybe the reason you don't see it is because you have no
<dsn>in your log4j config and so it does not enter any of the if conditionsbretthoerner commentedon Oct 17, 2016
I set my DSN externally with an environment variable, and am using an
httpsconnection, so that is weird. I see what you mean though (even though I can't seem to reproduce it).loucasa commentedon Oct 17, 2016
my log4j version is 2.6.1 if it makes any difference
bretthoerner commentedon Oct 17, 2016
Thanks @loucasa that makes a lot more sense to me, I'll see about a fix.
bretthoerner commentedon Oct 28, 2016
For the life of me I can't reproduce this with log4j2 2.6.1. Logging set to
allorinfo, DSN set to HTTP (I see Sentry INFO logging about the connection too). What is your slf4j version?loucasa commentedon Oct 31, 2016
slf4j.version=1.7.21. I wonder if its the sequence of events, if you step though it, is the first log event from
com.getsentry.raven.DefaultRavenFactory.createConnection()or your applications first log event? Mine is from the app. Another thing to check is whether anything inorg.apache.logging.log4j.core.config.AppenderControl.shouldSkip()prevents the recursive call.bretthoerner commentedon Feb 3, 2017
I tried chasing this down again to no avail. It's interesting that a user above fixed this in an older version by filtering out all Sentry logs from Sentry itself, which we do now for all logging frameworks.
I've realized that our documentation and example logging configurations were pretty poor, because I don't understand why you'd actually want to set the Sentry appender to anything below
WARN. Our example apparently told people to configure Sentry atALLwhich is just a bad idea all around. But, most of all, I can't seem to reproduce this at all.That said, I'm going to improve the docs/examples so that Sentry is filtered to
WARNand above -- and if this is an actual production issue for anyone I'd be curious on the details or an example mini project I can use to repro.darmbrust commentedon Dec 16, 2019
FYI, probably not related to this bug, but for anyone else that stumbles here from a google search for errors with recursive warnings from log4j:
https://issues.apache.org/jira/browse/LOG4J2-2738
ref: revert type assignment (#139)