You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2011/08/01 20:02:19 UTC
DO NOT REPLY [Bug 51597] New: JDBCAppender not closed due to SQL
Exception while executing an SQL
https://issues.apache.org/bugzilla/show_bug.cgi?id=51597
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
Log4j-JDBC-Appender-Issue.doc
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();
stmt.executeUpdate(sql);
} catch (SQLException e) {
throw e;
}finally{
try{
if(null != stmt)
stmt.close();
closeConnection(con);
} catch (SQLException e){
}
}
}
public void flushBuffer() {
//Do the actual logging
removes.ensureCapacity(buffer.size());
for (Iterator i = buffer.iterator(); i.hasNext();) {
try {
LoggingEvent logEvent = (LoggingEvent)i.next();
String sql = getLogStatement(logEvent);
removes.add(logEvent);
execute(sql);
}catch (SQLException e) {
errorHandler.error("Failed to excute sql", e,
ErrorCode.FLUSH_FAILURE);
}
}
// remove from the buffer any events that were reported
buffer.removeAll(removes);
// clear the buffer of reported events
removes.clear();
}
--
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
DO NOT REPLY [Bug 51597] JDBCAppender not closed due to SQL
Exception while executing an SQL
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51597
Anurag Agarwal <an...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anurag08agarwal@gmail.com
--
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
DO NOT REPLY [Bug 51597] JDBCAppender not closed due to SQL
Exception while executing an SQL
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51597
grobmeier <gr...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #1 from grobmeier <gr...@gmail.com> 2012-01-13 23:17:15 UTC ---
fixed with rv1231387
Thanks for the report!
--
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