logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51597] New: JDBCAppender not closed due to SQL Exception while executing an SQL
Date Mon, 01 Aug 2011 18:02:19 GMT

             Bug #: 51597
           Summary: JDBCAppender not closed due to SQL Exception while
                    executing an SQL
           Product: Log4j
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: Appender
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: anurag08agarwal@gmail.com
    Classification: Unclassified

Created attachment 27339
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=27339

In JDBCAppender.java there is method execute(String sql). This method is used
to insert the SQL into DB, but in case if anything wrong happen while
inserting, then it throws one SQLException and closing only SQL statement but
connection is not closed, and so Appender thread is still alive.

Now as the execute method is called via flushBuffer() method, this method is
calling execute and then event is added to removes list, but if execute method
had thrown the SQLException then the event is not added to removes list and
removes list is growing continuously. And that is in the buffer tile next call
of System.gc(), so this will make the next threads to go into hung state.

Code Snippet having issue is attached.
A solution to this is to have following implementation:

protected void execute(String sql) throws SQLException {
Connection con = null;
Statement stmt = null;
try {
    con = getConnection();
          stmt = con.createStatement();
     } catch (SQLException e) {
        throw e; 

    if(null != stmt)  

    } catch (SQLException e){



public void flushBuffer() {
//Do the actual logging
for (Iterator i = buffer.iterator(); i.hasNext();) {
try {
  LoggingEvent logEvent = (LoggingEvent)i.next();
  String sql = getLogStatement(logEvent);
  }catch (SQLException e) {
      errorHandler.error("Failed to excute sql", e,
// remove from the buffer any events that were reported
// clear the buffer of reported events

Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message