Atomikos Forum

Unexpected method invocation if SQL Trace is active

In my configuration I use Spring (3.1.0), Postgres (9.x) and Atomikos (3.7.1) running with Tomcat 7. When invoking the entity manager the first time, several initializations are done. Within a long chain of calls finally the connection is closed. During this process also AtomikosConnectionProxy.invoke is called with method close which works okay. Basically this looks like this (class is LoggingConnectionDecorator):

  public void close() throws SQLException {
            long start = System.currentTimeMillis();     
            try {
            } finally {
                if (_logs.isJDBCEnabled())
                    _logs.logJDBC("close", start, this);

After the close the method _logs.logJDBC is called if SQL Trace is active. This call results in a method of class DataSourceLogs.log which does also this call:

 if (conn != null)
            buf.append(", ").append(conn);

where conn is a LoggingConnectionDecorator.LoggingConnection.

The append(conn) results in a toString method of conn which looks like this:

 public String toString() {
        StringBuffer buf = new StringBuffer("conn ").append(hashCode());
        return buf.toString();

Method hasCode looks like this:

  public int hashCode() {
        return getInnermostDelegate().hashCode();

Method getInnermostDelegate returns an AtomikosConnectionProxy and the invocation of method hashCode invokes finally the invoke method of  AtomikosConnectionProxy.

Within this invoke method it comes to the following code fragment:

        if ( closed && !methodName.equals("close") ) {
            if ( reaped ) {
                //'reaped' is a system-triggered variant of closed -> throw exception that explains this
                String msg = "Connection has been reaped - calling " + methodName + " is no longer allowed! Increase reapTimeout to avoid this problem.";
                AtomikosSQLException.throwAtomikosSQLException ( msg );
            } else {
                String msg = "Connection was already closed - calling " + methodName + " is no longer allowed!";
                AtomikosSQLException.throwAtomikosSQLException ( msg );
            return null;

In my case variable close is true (it was called before the sql trace) and the method name is „hashCode“. Therefore the condition is true. Further reaped is false, so it comes to the else case where the exception „Connection was already closed ...“ is thrown.

I'm not sure what is wrong or should be rearranged in the invoke method. Obviously you don't expect that hashCode is called after a close. Maybe you should accept methods like toString, hashCode and that like, even after a close because these kind of methods have nothing to do with protocol violations. Or even better you should check explicitly for method calls which have something to do with the protocol (like close and that like) and accept all the others by default. The only way to make my configuration to work without an exception is to turn SQL Traces off.

Best regards,
Georg Nozicka Send private email
Thursday, April 12, 2012

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics