Bug 61391

Summary: SlowQueryReport not logging Failed Query if connection abandoned
Product: Tomcat 8 Reporter: Craig Webb <c.webb>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: regression    
Priority: P2    
Version: 8.5.x-trunk   
Target Milestone: ----   
Hardware: PC   
OS: All   

Description Craig Webb 2017-08-08 13:50:49 UTC
In SlowQueryReport.reportFailedQuery() a change has been made to check if QueryStats is null before calling QueryStats.failure(). However, the logging is also included in this if block.

The logging should happen regardless of whether QueryStats is null or not, so that the SQL is logged.

Current code:
QueryStats qs = this.getQueryStats(sql);
if (qs != null) {
   qs.failure(delta, now);
   if (isLogFailed() && log.isWarnEnabled()) {
      log.warn("Failed Query Report SQL="+sql+"; time="+delta+" ms;");
   }
}

Suggested fix:
QueryStats qs = this.getQueryStats(sql);
if (qs != null) {
   qs.failure(delta, now);
}
if (isLogFailed() && log.isWarnEnabled()) {
   log.warn("Failed Query Report SQL="+sql+"; time="+delta+" ms;");
}
Comment 1 Mark Thomas 2017-08-30 21:15:54 UTC
Thanks for the report and the suggested fix.

Fixed in:
- trunk for 9.0.0.M27 onwards
- 8.5.x for 8.5.21 onwards
- 8.0.x for 8.0.47 onwards
- 7.0.x for 7.0.82 onwards