I believe I've discovered an issue with
JdbcAdapterInternalService.begin() and JBoss' datasources -- JBoss is
closing the connection (active record isn't and is holding onto it to
boot!), then when the code attempts to start a transaction with a closed
connection, errors are thrown.

I've followed the format of other methods such that if the connection is
stale, to request a new connection.  It seems to be working thus far;
I've not seen errors as yet (other than the complaints about not having
closed connections and that the connection pool is closing them).

I have tried setting ActiveRecord::Base.allow_concurrency = true, but it
didn't do much more than to cause the jvm hang and run out of memory.

Long story short, I've attached the patch, if anyone is interested.

I'm still curious about why the connections aren't getting closed
properly, but I'm entering day 4 of a migraine and I'm late on a
deadline, so I don't have the time/energy to commit to it I'd like.
Perhaps soon, but if anyone has any ideas, I'd like to hear them.

Matt

Index: JdbcAdapterInternalService.java
===================================================================
--- JdbcAdapterInternalService.java	(revision 679)
+++ JdbcAdapterInternalService.java	(working copy)
@@ -205,8 +205,21 @@
     }
 
     public static IRubyObject begin(IRubyObject recv) throws SQLException {
-        ((Connection)recv.dataGetStruct()).setAutoCommit(false);
-        return recv.getRuntime().getNil();
+	while (true){
+	    Connection c = (Connection) recv.dataGetStruct();
+	    try {
+		c.setAutoCommit(false);
+		return recv.getRuntime().getNil();
+	    } catch (SQLException e) {
+		if(c.isClosed()) {
+                    recv = recv.callMethod(recv.getRuntime().getCurrentContext(),"reconnect!");
+                    if(!((Connection)recv.dataGetStruct()).isClosed()) {
+                        continue;
+                    }
+                }
+                throw e;
+	    }
+	}
     }
 
     public static IRubyObject commit(IRubyObject recv) throws SQLException {
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to