JRuby

NPE at Connection Shutdown

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    JRuby 1.1.1/AR-JDBC 0.8
  • Number of attachments :
    1

Description

I am getting occasional NPE while running my unit tests. I don't have a reproducible test case (it happens occasionally), but by the look of the site of exception, it looks like it may be fixed just be looking at the code. I don't know enough of the internals to be able to fix it myself, but I am hoping that someone who knows can use the NPE report to figure out where the bug is.

Exception in thread "Tasker" java.lang.NullPointerException
at jdbc_adapter.JdbcAdapterInternalService.rollback(JdbcAdapterInternalService.java:400)
at jdbc_adapter.JdbcAdapterInternalServiceInvoker$rollback_s_method_0_0.call(Unknown Source)
at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZero.call(JavaMethod.java:82)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:66)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:235)
at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:658)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:309)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:169)
at org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:172)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:148)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:223)
at org.jruby.runtime.CallSite$InlineCachingCallSite.cacheAndCall(CallSite.java:116)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:270)
at org.jruby.evaluator.ASTInterpreter.vcallNode(ASTInterpreter.java:1746)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:485)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:632)
........

Activity

Hide
Peter K Chan added a comment -

I should mention that the "Connection Shutdown" timing is only a conjecture, I am currently not able to track down the life cycle of where the bug occurs, so I am just guessing that the exception happens at shutdown.

Show
Peter K Chan added a comment - I should mention that the "Connection Shutdown" timing is only a conjecture, I am currently not able to track down the life cycle of where the bug occurs, so I am just guessing that the exception happens at shutdown.
Hide
Peter K Chan added a comment -

I have retested my app under JRuby 1.1.2 and the 0.8.1 release, and I am still getting the following error in my unit tests.

Exception in thread "Tasker" java.lang.NullPointerException
at jdbc_adapter.JdbcAdapterInternalService.rollback(JdbcAdapterInternalService.java:414)
at jdbc_adapter.JdbcAdapterInternalServiceInvoker$rollback_s_method_0_0.call(Unknown Source)
at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZero.call(JavaMethod.java:82)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:66)
...

I don't have a build environment to debug or build the JDBC adapter code, but looking at the stacktrace and the fact that it happens on connection shutdown, it seems like a null check will fix this:

JdbcAdapterInternalService.java, line 414

public static IRubyObject rollback(IRubyObject recv) throws SQLException {
Connection c = getConnection(recv);
if (!c.getAutoCommit()) { // add check here to see if c is null.
try { c.rollback(); } finally { c.setAutoCommit(true); }
}
return recv.getRuntime().getNil();
}

Show
Peter K Chan added a comment - I have retested my app under JRuby 1.1.2 and the 0.8.1 release, and I am still getting the following error in my unit tests. Exception in thread "Tasker" java.lang.NullPointerException at jdbc_adapter.JdbcAdapterInternalService.rollback(JdbcAdapterInternalService.java:414) at jdbc_adapter.JdbcAdapterInternalServiceInvoker$rollback_s_method_0_0.call(Unknown Source) at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZero.call(JavaMethod.java:82) at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:66) ... I don't have a build environment to debug or build the JDBC adapter code, but looking at the stacktrace and the fact that it happens on connection shutdown, it seems like a null check will fix this: JdbcAdapterInternalService.java, line 414 public static IRubyObject rollback(IRubyObject recv) throws SQLException { Connection c = getConnection(recv); if (!c.getAutoCommit()) { // add check here to see if c is null. try { c.rollback(); } finally { c.setAutoCommit(true); } } return recv.getRuntime().getNil(); }
Hide
Peter K Chan added a comment -

Here is a one line patch for the issue.

Show
Peter K Chan added a comment - Here is a one line patch for the issue.
Hide
Charles Oliver Nutter added a comment -

Nice, thanks for the patch. Marking for 1.1.3 and assigning to Nick...but whoever has access can go ahead and apply this.

Show
Charles Oliver Nutter added a comment - Nice, thanks for the patch. Marking for 1.1.3 and assigning to Nick...but whoever has access can go ahead and apply this.
Hide
Thomas E Enebo added a comment -

In auditing the current code, I believe this issue was fixed by forcing an error check in getConnection. Since we pass error as true, we will raise a Ruby exception if there is no connection (e.g. connection == null). Please reopen if I am wrong.

Show
Thomas E Enebo added a comment - In auditing the current code, I believe this issue was fixed by forcing an error check in getConnection. Since we pass error as true, we will raise a Ruby exception if there is no connection (e.g. connection == null). Please reopen if I am wrong.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: