Hello,<br><br>I think moving r.lock(); outside of the try block WILL help, because the original exception will no longer be hidden.<br><br>
&gt; Looking at this exception and related code in AppenderAttachableImpl,<br>
&gt; moving the r.lock(); statement outside of the try block will not<br>
&gt; change anything because I believe that r.lock() does not throw<br>
&gt; exceptions. However, looking at ReentrantReadWriteLock.<div class="Wj3C7c">ReadLock class&#39;<br>
&gt; lock() method, one is directed to the ReentrantReadWriteLock.Sync<br>
&gt; class and its acquireShared() method. If this method fails to acquire<br>
&gt; the lock due to a RuntimeException, then the subsequent r.unlock()<br>
&gt; call will fail with an IllegalMonitorStateException.<br><br>but if I understand correctly there will be no subsequent call to r.unlock in this case ??<br><br><pre>  <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">int</strong> appendLoopOnAppenders(E e) {<br>
<a name="56" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#56"></a>    <strong class="jxr_keyword">int</strong> size = 0;<br><a name="58" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#58"></a>    r.lock();<br>
<a name="57" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#57"></a>    <strong class="jxr_keyword">try</strong> {<br><a name="59" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#59"></a>      <strong class="jxr_keyword">for</strong> (Appender&lt;E&gt; appender : appenderList) {<br>
<a name="60" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#60"></a>        appender.doAppend(e);<br><a name="61" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#61"></a>        size++;<br>
<a name="62" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#62"></a>      }<br><a name="63" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#63"></a>    } <strong class="jxr_keyword">finally</strong> {<br>
<a name="64" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#64"></a>      r.unlock();<br><a name="65" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#65"></a>    }<br>
<a name="66" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#66"></a>    <strong class="jxr_keyword">return</strong> size;<br><a name="67" href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#67"></a>  }<br>
<br>Noiw, when r.lock() throws a RuntimeException, this one will be propagated to the caller, and we don&#39;t reach r.unlock(), right ?<br><br>Maarten</pre><br><br>&nbsp;In any case,<br>
&gt; r.lock() will not throw an exception since the exception is absorbed<br>
&gt; by the sync.acquireShared method.<br>
</div><br><br><br><br><div class="gmail_quote">On Tue, Feb 3, 2009 at 12:43 PM, Szel, Zoltan (IDEAS) <span dir="ltr">&lt;<a href="mailto:Zoli.Szel@morganstanley.com">Zoli.Szel@morganstanley.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
Unfortunately not, we cannot reproduce it but we have the strong feeling this is about out of memory as you mentioned.<br>
<br>
Regards,<br>
Zoltan Szel<br>
Morgan Stanley | IDEAS Practice Areas<br>
<div class="Ih2E3d">Lechner Odon fasor 8 | Floor 07<br>
Budapest, 1095<br>
Phone: +36 1 881-3978<br>
Zoli.Szel@MorganStanley.com<br>
<br>
</div><div><div></div><div class="Wj3C7c">-----Original Message-----<br>
From: Ceki Gulcu [mailto:<a href="mailto:ceki@qos.ch">ceki@qos.ch</a>]<br>
Sent: Monday, February 02, 2009 11:17 PM<br>
To: logback developers list<br>
Subject: Re: [logback-dev] IllegalMonitorStateException in AppenderAttachableImpl.appendLoopOnAppenders()<br>
<br>
<br>
Any luck reproducing this issue?<br>
<br>
Ceki Gulcu wrote:<br>
&gt; Hello Zoltan,<br>
&gt;<br>
&gt; Looking at this exception and related code in AppenderAttachableImpl,<br>
&gt; moving the r.lock(); statement outside of the try block will not<br>
&gt; change anything because I believe that r.lock() does not throw<br>
&gt; exceptions. However, looking at ReentrantReadWriteLock.ReadLock class&#39;<br>
&gt; lock() method, one is directed to the ReentrantReadWriteLock.Sync<br>
&gt; class and its acquireShared() method. If this method fails to acquire<br>
&gt; the lock due to a RuntimeException, then the subsequent r.unlock()<br>
&gt; call will fail with an IllegalMonitorStateException. In any case,<br>
&gt; r.lock() will not throw an exception since the exception is absorbed<br>
&gt; by the sync.acquireShared method.<br>
&gt;<br>
&gt; It would be quite helpful if you were able to reproduce the problem.<br>
&gt;<br>
&gt; We could place the r.unlock() invocation within a try/catch block<br>
&gt; (absorbing the IllegalMonitorStateException you got). However, this is<br>
&gt; may only obfuscate the real cause of the problem, that is an<br>
&gt; OutOfMemoryException or such. We could also imagine that there is a<br>
&gt; bug in ReentrantReadWriteLock. Given its complexity, it&#39;s not such an<br>
&gt; outlandish hypothesis.<br>
&gt;<br>
&gt; Otherwise, the only remaining possibility is a bug in logback. But we<br>
&gt; all know that is impossible.<br>
&gt;<br>
&gt; More seriously, I think this bug will be hard to nail down.<br>
&gt;<br>
&gt; Szel, Zoltan (IDEAS) wrote:<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; We have hit the exception mentioned in the subject in one of our<br>
&gt;&gt; applications. We are using JDK 6 and Logback 0.9.14. &nbsp;Here is the<br>
&gt;&gt; stacktrace:<br>
&gt;&gt;<br>
&gt;&gt; Caused by: java.lang.IllegalMonitorStateException<br>
&gt;&gt; &nbsp;at<br>
&gt;&gt; java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryReleaseShared(ReentrantReadWriteLock.java:363)<br>
&gt;&gt;<br>
&gt;&gt; &nbsp;at<br>
&gt;&gt; java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1253)<br>
&gt;&gt;<br>
&gt;&gt; &nbsp;at<br>
&gt;&gt; java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.unlock(ReentrantReadWriteLock.java:745)<br>
&gt;&gt;<br>
&gt;&gt; &nbsp;at<br>
&gt;&gt; ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:64)<br>
&gt;&gt;<br>
&gt;&gt; &nbsp;at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)<br>
&gt;&gt; &nbsp;at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)<br>
&gt;&gt; &nbsp;at<br>
&gt;&gt; ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:439)<br>
&gt;&gt; &nbsp;at ch.qos.logback.classic.Logger.filterAndLog_1(Logger.java:411)<br>
&gt;&gt; &nbsp;at ch.qos.logback.classic.Logger.debug(Logger.java:504)<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; I have checked the code and it seems to me this can only happen if the<br>
&gt;&gt; readLock.lock() method throws an exception:<br>
&gt;&gt;<br>
&gt;&gt; *public* *int* appendLoopOnAppenders(E e) {<br>
&gt;&gt;<br>
&gt;&gt; 56<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#56" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#56</a>&gt;<br>
&gt;&gt; *int* size = 0;<br>
&gt;&gt;<br>
&gt;&gt; 57<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#57" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#57</a>&gt;<br>
&gt;&gt; *try* {<br>
&gt;&gt;<br>
&gt;&gt; 58<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#58" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#58</a>&gt;<br>
&gt;&gt; r.lock();<br>
&gt;&gt;<br>
&gt;&gt; 59<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#59" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#59</a>&gt;<br>
&gt;&gt; *for* (Appender&lt;E&gt; appender : appenderList) {<br>
&gt;&gt;<br>
&gt;&gt; 60<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#60" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#60</a>&gt;<br>
&gt;&gt; appender.doAppend(e);<br>
&gt;&gt;<br>
&gt;&gt; 61<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#61" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#61</a>&gt;<br>
&gt;&gt; size++;<br>
&gt;&gt;<br>
&gt;&gt; 62<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#62" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#62</a>&gt;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; 63<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#63" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#63</a>&gt;<br>
&gt;&gt; } *finally* {<br>
&gt;&gt;<br>
&gt;&gt; 64<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#64" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#64</a>&gt;<br>
&gt;&gt; r.unlock();<br>
&gt;&gt;<br>
&gt;&gt; 65<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#65" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#65</a>&gt;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; 66<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#66" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#66</a>&gt;<br>
&gt;&gt; *return* size;<br>
&gt;&gt;<br>
&gt;&gt; 67<br>
&gt;&gt; &lt;<a href="http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#67" target="_blank">http://logback.qos.ch/xref/ch/qos/logback/core/spi/AppenderAttachableImpl.html#67</a>&gt;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; if r.lock() in line 58 throws an exception for some reason than in the<br>
&gt;&gt; finally block the unlock will throw also an exception which will hide<br>
&gt;&gt; the original one. I cannot see any other reason why the unlock would<br>
&gt;&gt; throw this exception in this scenario. I am not yet able to reproduce<br>
&gt;&gt; it, but I thought this exception worth a mail. The only suggestion I<br>
&gt;&gt; have for now is to move the r.lock() call out of the try block,<br>
&gt;&gt; because if that is the bad guy, than we would have the original<br>
&gt;&gt; exception propagated.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; If I have more information on this issue I will update this thread.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Regards,<br>
&gt;&gt;<br>
&gt;&gt; Zoltan Szel<br>
&gt;&gt; *Morgan Stanley | IDEAS PRACTICE AREAS<br>
&gt;&gt; *Lechner Odon fasor 8 | Floor 07<br>
&gt;&gt; Budapest, 1095<br>
&gt;&gt; Phone: +36 1 881-3978<br>
&gt;&gt; Zoli.Szel@MorganStanley.com &lt;mailto:<a href="mailto:Zoli.Szel@MorganStanley.com">Zoli.Szel@MorganStanley.com</a>&gt;<br>
&gt;&gt;<br>
&gt;&gt; ------------------------------------------------------------------------<br>
&gt;&gt;<br>
&gt;&gt; NOTICE: If received in error, please destroy and notify sender. Sender<br>
&gt;&gt; does not intend to waive confidentiality or privilege. Use of this<br>
&gt;&gt; email is prohibited when received in error.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; ------------------------------------------------------------------------<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; logback-dev mailing list<br>
&gt;&gt; logback-dev@qos.ch<br>
&gt;&gt; <a href="http://qos.ch/mailman/listinfo/logback-dev" target="_blank">http://qos.ch/mailman/listinfo/logback-dev</a><br>
&gt;<br>
<br>
--<br>
Ceki Gülcü<br>
Logback: The reliable, generic, fast and flexible logging framework for Java.<br>
<a href="http://logback.qos.ch" target="_blank">http://logback.qos.ch</a><br>
<br>
</div></div>--------------------------------------------------------------------------<br>
<div><div></div><div class="Wj3C7c">NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.<br>

_______________________________________________<br>
logback-dev mailing list<br>
logback-dev@qos.ch<br>
<a href="http://qos.ch/mailman/listinfo/logback-dev" target="_blank">http://qos.ch/mailman/listinfo/logback-dev</a><br>
</div></div></blockquote></div><br>