Bug 861907

Summary: NPE thrown in SqlTableGatewayListener.getDbConn() causes the listener to stop polling
Product: [JBoss] JBoss Enterprise SOA Platform 5 Reporter: Adam Kovari <akovari>
Component: JBossESBAssignee: tcunning
Status: ON_QA --- QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 5.2.0 GA, 5.3.0 GACC: nobody, rwagner, soa-p-jira, tasato, tcunning
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 862048    

Description Adam Kovari 2012-10-01 10:12:41 UTC
Description of problem:
Listener is not fetching the data from the database after the Data source disconnect and reconnect. To resolve the issue we have to redeploy the esb.

Version-Release number of selected component (if applicable):
JBoss SOA-P 5.2.0

How reproducible:
always

Steps to Reproduce:
1. deploy ESB project which uses SQL listener
2. restart database, wait few minutes
3. notice that SQL listener is stopped
  
Actual results:
SQL listener not polling

Expected results:
SQL listener polling

Additional info:
Proposed fix:
Index: src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	(revision 37737)
+++ src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	(working copy)
@@ -507,7 +507,7 @@
         	    RS.close();
         	
                 oConn.rollback();
-            } catch (final SQLException sqle) {
+            } catch (Exception ex) {
             	refreshDatasource();
             }

Comment 1 Rick Wagner 2012-10-01 18:28:09 UTC
This BZ is for SOA-P 5.2.  Please be aware there is an associated BZ for SOA-P 5.3. (BZ 862055)

This BZ is currently associated with SOA-P 5.2 Rollup SOA_5.2_2_2012.

The SOA-P 5.3 BZ (BZ 862055) is currently associated with Rollup SOA_5.3_2_2012.

Comment 2 JBoss JIRA Server 2012-10-02 06:27:01 UTC
Tadayoshi Sato <tadayosi> made a comment on jira JBESB-3853

Proposed fix by Martin Weiler:
Index: src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	(revision 37737)
+++ src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	(working copy)
@@ -507,7 +507,7 @@
         	    RS.close();
         	
                 oConn.rollback();
-            } catch (final SQLException sqle) {
+            } catch (Exception ex) {
             	refreshDatasource();
             }

Comment 3 JBoss JIRA Server 2012-10-02 06:27:33 UTC
Tadayoshi Sato <tadayosi> made a comment on jira JBESB-3853

Proposed fix by Martin Weiler:
{code}
Index: src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	(revision 37737)
+++ src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	(working copy)
@@ -507,7 +507,7 @@
         	    RS.close();
         	
                 oConn.rollback();
-            } catch (final SQLException sqle) {
+            } catch (Exception ex) {
             	refreshDatasource();
             }
{code}

Comment 4 JBoss JIRA Server 2012-10-02 06:34:30 UTC
Tadayoshi Sato <tadayosi> made a comment on jira JBESB-3853

In the source code of JBoss ESB 4.10, the following object {{"oConn"}} can be null and subsequently a NPE can happen because after the first successful invocation of {{getDbConn()}} the datasource gets out of service.
{code}
473         final JdbcCleanConn oConn = getDbConn();
{code}
After the initial run of {{getDbConn()}} the {{JdbcCleanConn}} object is cached to_the {{dbConn}} field, so the following if block won't be executed subsequently.
{code}
544     protected JdbcCleanConn getDbConn() {
545       DataSource oDS = null;
546         if (null == _dbConn) {
...
566           _dbConn = new JdbcCleanConn(oDS, transacted);
567         }
{code}
And rushing directly into the following line with shortage of the datasource will raise a {{SQLException}} and execute {{releaseDBConnection()}} in the catch block, where is exactly the place of resetting the {{dbConn}} field to null.
{code}
569         if ((null != _dbConn) && (_dbConn.getStatements().size() == 0)) {
570           try {
571             prepareStatements(); 
572           } catch (SQLException e) {
573             releaseDBConnection();
574         _   logger.warn("Exception preparing statements", e);
575           }
576         }
{code}
That's why we will have a NPE at the following line 509 and eventually {{SqlTableGatewayListener}} will stop.
{code}
471     protected List<Map<String, Object>> pollForCandidates() {
...
473         final JdbcCleanConn oConn = getDbConn();
...
509                 oConn.rollback();
{code}
So, I'd say the {{SqlTableGatewayListener}} can terminate forever regardless of the datasource being recovered later in such a scenario that the datasource becomes unavailable temporarily and have failed to make prepared statements by chance.

Comment 5 JBoss JIRA Server 2012-10-02 08:01:17 UTC
Tadayoshi Sato <tadayosi> made a comment on jira JBESB-3853

It seems to be a direct consequence of the changes applied for:
https://issues.jboss.org/browse/JBESB-3282
https://issues.jboss.org/browse/SOA-2012

--> https://source.jboss.org/changelog/JBossESB?cs=32667

Comment 6 JBoss JIRA Server 2012-10-02 13:20:06 UTC
Tom Cunningham <tcunning> updated the status of jira JBESB-3854 to Resolved

Comment 7 JBoss JIRA Server 2012-10-02 16:06:48 UTC
Tom Cunningham <tcunning> updated the status of jira JBESB-3853 to Resolved

Comment 8 JBoss JIRA Server 2012-10-02 16:06:48 UTC
Tom Cunningham <tcunning> made a comment on jira JBESB-3853

Committed to 4.11 CP and to trunk.

Comment 9 JBoss JIRA Server 2012-10-02 16:06:56 UTC
Tom Cunningham <tcunning> updated the status of jira JBESB-3853 to Closed

Comment 10 JBoss JIRA Server 2012-10-02 16:07:03 UTC
Tom Cunningham <tcunning> updated the status of jira JBESB-3854 to Closed