This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 221602 - Hanged when trying to stop database query on Oracle database
Summary: Hanged when trying to stop database query on Oracle database
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.2
Hardware: PC Windows 7 x64
: P3 normal (vote)
Assignee: Jaroslav Havlin
URL:
Keywords:
: 172807 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-11-07 08:01 UTC by kolen
Modified: 2014-10-06 22:13 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump made with VisualVM (27.31 KB, text/plain)
2012-11-07 08:01 UTC, kolen
Details
Thread dump of the same problem from 7.3 beta (Build 201210011125) (29.45 KB, application/octet-stream)
2012-11-08 08:25 UTC, kolen
Details
Patch - timeout for Connection.isClosed() (2.35 KB, patch)
2012-11-09 17:41 UTC, Jaroslav Havlin
Details | Diff
Patch - timeout for Connection.isClosed() (2.30 KB, patch)
2012-11-12 13:37 UTC, Jaroslav Havlin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description kolen 2012-11-07 08:01:56 UTC
Created attachment 127273 [details]
Thread dump made with VisualVM

Hanged after trying to stop running database query on Oracle database. Not instantly hanged after pressing "stop", but after some time. Stopping query was unsuccessful, it wasn't stopped.

UI was not responding and not redrawing.

Attaching thread dump.
Comment 1 kolen 2012-11-07 13:54:06 UTC
Reproduced again:

- Started long query on Oracle database (thin driver).
- Pressed "x" after "Executing SQL statement(s)" to cancel. Not cancelled.
- Right-clicked node representing connection in 'Services' tree. UI hanged.
Comment 2 kolen 2012-11-07 14:02:23 UTC
Not reproduceable with doing the same with mysql. Tried to execute "select sleep(600);" on mysql, query started to execute. Stopping running query also had no effect (it continued running), but right-clicking anything in 'services' tab not caused UI to hang.

Oracle connection URL caused hang is: jdbc:oracle:thin:@//(host)/(service). Driver oracle.jdbc.OracleDriver, from instantclient-basic-windows.x64-11.2.0.3.0.zip.
Comment 3 Jaroslav Havlin 2012-11-07 15:34:07 UTC
Please, did you encounter the bug with 7.2 only, or also with 7.3?
Comment 4 kolen 2012-11-08 08:25:17 UTC
Tried in 7.3, it first hanged, but unfreezed after 50 seconds.
And stopping running query works in 7.3 unlike 7.2 where it not worked even for mysql. However it hanged before stopping, i.e. when running query, right-clicking connection node in 'services' tree causes UI to hang (but unhanged after 50 seconds).
So seems that unrelated to stopping running query, caused when right-clicking when query is running.

Tried mysql in 7.3 too, not caused hanging.
Comment 5 kolen 2012-11-08 08:25:28 UTC
Created attachment 127365 [details]
Thread dump of the same problem from 7.3 beta (Build 201210011125)
Comment 6 Jaroslav Havlin 2012-11-08 08:45:02 UTC
"AWT-EventQueue-1" prio=6 tid=0x000000000d87a800 nid=0x1b60 waiting for monitor entry [0x000000000ec8d000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at oracle.jdbc.driver.PhysicalConnection.isClosed
         (PhysicalConnection.java:4364)
	- waiting to lock <0x00000000d4656488> (!!!)
         (a oracle.jdbc.driver.T4CConnection)
	at org.netbeans.modules.db.explorer.DatabaseConnection
         .isVitalConnection(DatabaseConnection.java:291)
	at org.netbeans.modules.db.explorer.action.ExecuteCommandAction.enable
         (ExecuteCommandAction.java:66)
	at org.openide.util.actions.NodeAction$DelegateAction.resultChanged
         (NodeAction.java:615)
	at org.openide.util.actions.NodeAction$DelegateAction.<init>
         (NodeAction.java:560)
	at org.openide.util.actions.NodeAction.createContextAwareInstance
        (NodeAction.java:357)
	at org.openide.util.Utilities.actionsToPopup(Utilities.java:2754)
	at org.openide.util.Utilities.actionsToPopup(Utilities.java:2850)
	at org.openide.explorer.view.TreeView.createPopup(TreeView.java:1058)
        [...]

"SQLStatementExecution" daemon prio=2 tid=0x000000000d874800 nid=0x18d4 runnable [0x000000000c44e000]
        [...]
        at oracle.jdbc.driver.OracleStatement.execute
        (OracleStatement.java:1871)
        -locked <0x00000000d4656488> (a oracle.jdbc.driver.T4CConnection)(!!!)
	at oracle.jdbc.driver.OracleStatementWrapper.execute
         (OracleStatementWrapper.java:318)
	at org.netbeans.modules.db.dataview.output.SQLExecutionHelper
         .executeSQLStatement(SQLExecutionHelper.java:713)
	at org.netbeans.modules.db.dataview.output.SQLExecutionHelper
         .access$300(SQLExecutionHelper.java:81)
	at org.netbeans.modules.db.dataview.output.SQLExecutionHelper$1Loader
         .run(SQLExecutionHelper.java:147)
        [...]

Method DatabaseConnection.isVitalConnection needs to access locked driver.

Accessing the same connection from multiple threads should be prevented, or the check for valid connection fixed. We'll investigate possible solutions.

Thank you very much for your help!
Comment 7 Jaroslav Havlin 2012-11-09 17:41:24 UTC
Created attachment 127502 [details]
Patch - timeout for Connection.isClosed()

The problem is that a single (java.sql) Connection is used for running queries and for updating UI (e.g. deciding which actions are available).

I think that the best solution would be implementing a connection pool, but it would need some deeper changes and API review. This change seems to be quite risky for 7.3.

Simpler, more ugly, but still not ideal, is using a timeout in DatabaseConnection.isVitalConnection (the patch is attached).

Another solution is informing the DatabaseConnection that its java.sql.Connection is currently in use, which would make isVitalConnection return instantly. But it also requires more changes (including API).

Matthias, Jirka, please, do you have any opinions or ideas?
Comment 8 matthias42 2012-11-09 19:54:21 UTC
(In reply to comment #7)
> The problem is that a single (java.sql) Connection is used for running queries
> and for updating UI (e.g. deciding which actions are available).

I agree with this assessment.

> Simpler, more ugly, but still not ideal, is using a timeout in
> DatabaseConnection.isVitalConnection (the patch is attached).

This looks good. 

Actually following the documentation in http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html#isClosed%28%29 , the implementation in the oracle driver is unnecessarily strict with regard to delegating to the underlying physical connection. This could be discussed internaly.

The lock would needed only for Connection#isValid, as that method is expected to do some more checks (comparable to DatabaseConnection#test, judging from the documentation).

With regard to the patch, i would move the creation of the thread pool in line 313 to a static, else the idea is a bit defeated :-)

Apart from this, it looks good.
Comment 9 Jaroslav Havlin 2012-11-12 13:37:45 UTC
Created attachment 127621 [details]
Patch - timeout for Connection.isClosed()

> With regard to the patch, i would move the creation of the thread pool in line
> 313 to a static, else the idea is a bit defeated :-)
Thank you, attaching fixed patch (even existing static RequestProcessor can be used) [ashamed].
Comment 10 matthias42 2012-11-14 20:19:16 UTC
(In reply to comment #9)
> Created attachment 127621 [details]
> Patch - timeout for Connection.isClosed()
> 
> > With regard to the patch, i would move the creation of the thread pool in line
> > 313 to a static, else the idea is a bit defeated :-)
> Thank you, attaching fixed patch (even existing static RequestProcessor can be
> used) [ashamed].

Looks good.
Comment 11 Jaroslav Havlin 2012-11-16 09:36:59 UTC
http://hg.netbeans.org/core-main/rev/829141218633
Thank you very much for your help.
Comment 12 Quality Engineering 2012-11-17 02:45:06 UTC
Integrated into 'main-golden', will be available in build *201211170002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/829141218633
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #221602: Hanged when trying to stop database query on Oracle database
Comment 13 matthias42 2014-10-06 22:13:28 UTC
*** Bug 172807 has been marked as a duplicate of this bug. ***