<div dir="ltr"><div>My problem is now down to finding out how logback (or the java app) can hold <i>two</i> file handles for the same file.</div><div><br></div><div>I managed to verify that having the file open in another process, like glogg, when the rollover happened was enough to trigger the issue. Using Process Explorer from SysInternals or the Resource Monitor would show the file handle being used by both processes and after closing the other process. Once the other process was closed, another logging statement would then again trigger the rollover and delete the file (<i>usually</i>):</div><div><img src="cid:ii_kq8xyzz41" alt="Skjermbilde 2021-06-23 kl. 00.56.54.png" width="562" height="158"><img src="cid:ii_kq8xyzzf2" alt="Skjermbilde 2021-06-23 kl. 00.50.34.png" width="562" height="127"><br></div><div><br></div><div>The problem is that sometimes this situation arose:</div><div><br></div><img src="cid:ii_kq8xyzyo0" alt="Skjermbilde 2021-06-23 kl. 00.15.44.png" width="562" height="108"><div><br></div><div>There are three file handles, of which two belong to the java process. Killing the external process this time did nothing, as the java process itself prevented itself from deleting the file. I am not sure how this can happen? This is the real issue here. Either it is one thread holding two references or two threads holding one each. Trying to find out how to see which code/class/instance owns these file handles <a href="https://stackoverflow.com/questions/68091703/find-out-which-class-instance-holds-a-reference-to-an-open-file">is a problem of its own</a>. If you have any tips on how I can find out, please give me a tip - not rocking the OQL :)</div><div><br></div><div>Seeing that I am able to verify the issue quite easily on the server (lowering the file size for rollover to 50KB and opening the file in a log viewer) makes me optimistic that I should be able to verify it locally, as well. I think one fix for this issue is to simply try and truncate the file on failing to delete, as writing obviously works. That would get rid of the entire "recompress entire log file on each log statement" behavior it currently displays, without any immediate downsides, AFAIK.<br><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">tir. 22. jun. 2021 kl. 17:28 skrev Carl-Erik Kopseng <<a href="mailto:carlerik@diffia.com">carlerik@diffia.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi, for some weeks we have observed some really mysterious behavior when enabling one of our appenders. This appender was configured specially to use the `FixedWindowRollingPolicy`. What we observed, was that after some time of debug logging, the CPU would suddenly hit the roof and have at least one core fully pegged at 100%. Using Jprofiler we found the issue to be various cases of `logger.debug()` that would be used by this special appender. Disabling the appender immediately fixed the issue (as we have `scan=true`)</div><div><br></div><div>I debugged this yesterday and found the answer partly in the logs and in the logback code. This is the line that basically shows the issue:</div><div><pre style="box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,"SF Mono",Consolas,"Liberation Mono",Menlo,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;padding:16px;overflow:auto;line-height:1.45;border-radius:6px;word-break:normal"><span style="background-color:rgb(243,243,243)"><font color="#000000">   <span style="box-sizing:border-box">if</span> (<span style="box-sizing:border-box">!</span>file2zip<span style="box-sizing:border-box">.</span>delete()) {
        addStatus(<span style="box-sizing:border-box">new</span> <span style="box-sizing:border-box">WarnStatus</span>(<span style="box-sizing:border-box"><span style="box-sizing:border-box">"</span>Could not delete [<span style="box-sizing:border-box">"</span></span> <span style="box-sizing:border-box">+</span> nameOfFile2zip <span style="box-sizing:border-box">+</span> <span style="box-sizing:border-box"><span style="box-sizing:border-box">"</span>].<span style="box-sizing:border-box">"</span></span>, <span style="box-sizing:border-box">this</span>));
    }</font></span></pre></div><div><br></div><div>The logs were full of this and I also found references to this online. I documented the entire process and findings in this repo: <a href="https://github.com/fatso83/logback-bug" target="_blank">https://github.com/fatso83/logback-bug</a>. The repo also contains a minimal attempt at recreating what I saw on the Windows servers on my local machine. </div><div><br></div><div>I was unable to reproduce this locally, which I kind of need in order to fix this bug. So, I was just wondering if any of you had any tips? What could cause the file to be "locked" / prevented from being deleted? Would it be enough if someone had a read-handle on the file, for instance a log reader like `<a href="https://glogg.bonnefon.org" target="_blank">glogg</a>`? I made sure to close my own programs when looking at this, but there are multiple users that look at these logs.</div><div><br></div><div>There is a single JVM running this app.</div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><table cellpadding="0" cellspacing="0" border="0" style="background:none;margin:0px;padding:0px;border:0px;font-stretch:inherit;font-size:16px;line-height:inherit;font-family:proxima-nova,"Helvetica Neue",Helvetica,Arial,sans-serif;vertical-align:baseline;border-collapse:collapse;color:rgb(85,85,85)"><tbody style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font-family:Arial,Helvetica,sans-serif;padding:0px 0px 5px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:18px;line-height:inherit;vertical-align:baseline;color:rgb(0,151,137)">Carl-Erik Kopseng</td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:baseline;color:rgb(51,51,51)"><span style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline">Senior developer</span></td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:baseline;color:rgb(51,51,51)"><span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline">Diffia AS</span></td></tr></tbody></table></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><table cellpadding="0" cellspacing="0" border="0" style="background:none;margin:0px;padding:0px;border:0px;font-stretch:inherit;font-size:16px;line-height:inherit;font-family:proxima-nova,"Helvetica Neue",Helvetica,Arial,sans-serif;vertical-align:baseline;border-collapse:collapse;color:rgb(85,85,85)"><tbody style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font-family:Arial,Helvetica,sans-serif;padding:0px 0px 5px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:18px;line-height:inherit;vertical-align:baseline;color:rgb(0,151,137)">Carl-Erik Kopseng</td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:baseline;color:rgb(51,51,51)"><span style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline">Senior developer</span></td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:baseline;color:rgb(51,51,51)"><span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;font-stretch:inherit;font-size:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline">Diffia AS</span></td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td width="20" valign="top" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:top;width:20px;color:rgb(0,151,137)">m:</td><td style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:baseline;color:rgb(51,51,51)"><a href="tel:+4740065078" value="+4790743013" style="color:rgb(17,85,204)" target="_blank">+47 400 65 078</a></td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td width="20" valign="top" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:top;width:20px;color:rgb(0,151,137)">a:</td><td valign="top" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:top;color:rgb(51,51,51)">StartupLab, <a href="https://maps.google.com/?q=Gaustadall%C3%A9en+21,+0349,+Oslo,+norway&entry=gmail&source=g" style="color:rgb(17,85,204)" target="_blank">Gaustadalléen 21, 0349, Oslo, Norway</a></td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td width="20" valign="top" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:top;width:20px;color:rgb(0,151,137)"></td><td valign="top" style="font-family:Arial,Helvetica,sans-serif;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:14px;line-height:inherit;vertical-align:top;color:rgb(51,51,51)"></td></tr><tr style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline"><td colspan="2" style="font:inherit;padding:0px;border:0px;vertical-align:baseline"><a href="https://www.facebook.com/diffia/" style="color:rgb(29,161,219);margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline" target="_blank"><img width="25" height="25" src="http://cdn2.hubspot.net/hubfs/184235/dev_images/signature_app/facebook_sig.png" style="margin: 0px; padding: 0px; border: none; font: inherit; vertical-align: baseline; width: 25px; height: 25px; max-width: 25px; max-height: 25px;"></a>  <a href="https://www.linkedin.com/company/10602313/" style="color:rgb(29,161,219);margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline" target="_blank"><img width="25" height="25" src="http://cdn2.hubspot.net/hubfs/184235/dev_images/signature_app/linkedin_sig.png" style="margin: 0px; padding: 0px; border: none; font: inherit; vertical-align: baseline; width: 25px; height: 25px; max-width: 25px; max-height: 25px;"></a></td></tr></tbody></table></div></div>