Bug 57959 - Deadlock in FileHandler.java when log is rotated
Summary: Deadlock in FileHandler.java when log is rotated
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.62
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-27 19:21 UTC by Alex Chachanashvili
Modified: 2015-05-28 06:59 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Chachanashvili 2015-05-27 19:21:22 UTC
Tomcat 7 will deadlock when a log file is rotated.  This issue has been fixed in latest tomcat 6 and tomcat 8 but not in tomcat 7.

The issue is in following code (apache-tomcat-7.0.62-src/java/org/apache/juli/FileHandler.java:188)


                } finally {
                    writerLock.writeLock().unlock();
                    // Down grade to read-lock. This ensures the writer remains valid
                    // until the log message is written
                    writerLock.readLock().lock();
                }
            }


Despite the comment the order is wrong, you have to acquire a read lock then release write lock to make sure the race condition does not occur.

The correct way to do it is:

                } finally {
                    writerLock.readLock().lock();
                    writerLock.writeLock().unlock();
                }
            }

In tomcat 6 (apache-tomcat-6.0.44-src/java/org/apache/juli/FileHandler.java:187) and tomcat 8 (apache-tomcat-8.0.22-src/java/org/apache/juli/FileHandler.java:186) the order is correct.
Comment 1 Violeta Georgieva 2015-05-28 06:59:37 UTC
Thanks for the report.
The fix is provided for Tomcat 7 trunk and will be available with 7.0.63 onwards.

Regards,
Violeta