Issue Details (XML | Word | Printable)

Key: JDBC-400
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mark Rotteveel
Reporter: Attila Molnár
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Jaybird JCA/JDBC Driver

org.firebirdsql.jdbc.FBSQLException: Exception. couldn't close blob: org.firebirdsql.gds.GDSException: invalid BLOB handle

Created: 05/Jun/15 01:42 PM   Updated: 19/Oct/15 03:40 PM
Component/s: None
Affects Version/s: Jaybird 2.2, Jaybird 2.2.1, Jaybird 2.2.2, Jaybird 2.2.3, Jaybird 2.2.4, Jaybird 2.2.5, Jaybird 2.2.6, Jaybird 2.2.7, Jaybird 2.2.8
Fix Version/s: Jaybird 2.2.9, Jaybird 3.0.0

File Attachments: 1. Zip Archive TEST.ZIP (44 kB)

Issue Links:
Relate
 


 Description  « Hide
Hi Mark!

org.apache.commons.dbcp2.BasicDataSource ds = new BasicDataSource();//dbcp2!
ds.setUsername("SYSDBA");
ds.setPassword("masterkey");
ds.setUrl("jdbc:firebirdsql:l3s-4/3051:d:\\\\test.fdb?charSet\\=UTF-8&TRANSACTION_READ_COMMITTED\\=isc_tpb_read_committed,isc_rec_version,isc_tpb_nowait&isc_dpb_sql_dialect=1");
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
PreparedStatement s = conn.prepareStatement("SELECT blob_data from test");
ResultSet rs = s.executeQuery();
rs.next();
InputStream is = rs.getBinaryStream(1);
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamUtils.copy(is, os);
conn.rollback();
conn.close();

Error on conn.close() call.

Works fine with org.apache.commons.dbcp.BasicDataSource.

It this a Jaybird or a commons-dbcp2 BasicDataSource bug?



Thank you!

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Mark Rotteveel added a comment - 05/Jun/15 02:21 PM - edited
The blob is getting closed by the rollback, but Jaybird seems to think it is still open and then tries to close it again on close of the connection.

Mark Rotteveel added a comment - 05/Jun/15 02:35 PM - edited
I can reproduce this in earlier version as well (I tried Jaybird 2.2.7, 2.2.4, 2.2.0 and 2.1.6). It has essentially always been broken. It is not related to DBCP as it is also reproducible without DBCP.

Simplest code to reproduce is:

        Connection conn = DriverManager.getConnection(JDBC_URL, USER_NAME, PASSWORD);
        conn.setAutoCommit(false);
        PreparedStatement s = conn.prepareStatement("SELECT filedata FROM imagestorage");
        ResultSet rs = s.executeQuery();
        rs.next();
        rs.getBinaryStream(1);
        conn.rollback();
        conn.close();

Workaround for this problem: use try-with-resources for the result set and for the inputstream obtained from the result set (or explicitly close() the input stream), eg:

        Connection conn = DriverManager.getConnection(JDBC_URL, USER_NAME, PASSWORD);
        conn.setAutoCommit(false);
        PreparedStatement s = conn.prepareStatement("SELECT filedata FROM imagestorage");
        try (ResultSet rs = s.executeQuery()) {
                rs.next();
                try (InputStream is = rs.getBinaryStream(1)) {
                    // Do something with is
                }
        }
        conn.rollback();
        conn.close();

Mark Rotteveel added a comment - 05/Jun/15 02:39 PM
Root cause seems to be JDBC-307.

Mark Rotteveel added a comment - 05/Jun/15 02:42 PM
As to why it did work with DBCP 1, I'd guess that DBCP 1 explicitly closes the result set before roll back, and DBCP 2 trusts the driver to do the right thing. I haven't looked at the DBCP code though, so that is just a guess.

Mark Rotteveel added a comment - 05/Jun/15 02:45 PM
Rescheduled JDBC-307 for 2.2.9; I will keep this ticket open and track it separately to improve test coverage.

Attila Molnár added a comment - 08/Jun/15 09:46 AM
Hi!

Using InputStream and ResultSet close() worked.

Thank You!

Mark Rotteveel added a comment - 11/Jul/15 08:16 AM
Added extra tests to verify fix of JDBC-307 also fixed this.