Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.firebirdsql.jdbc.FBSQLException: Exception. couldn't close blob: org.firebirdsql.gds.GDSException: invalid BLOB handle [JDBC400] #181

Closed
firebird-automations opened this issue Jun 5, 2015 · 13 comments

Comments

@firebird-automations
Copy link

Submitted by: Attila Molnár (e_pluribus_unum)

Is related to JDBC307

Attachments:
TEST.ZIP

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!

Commits: 30bfd96 9dc237e

@firebird-automations
Copy link
Author

Modified by: Attila Molnár (e_pluribus_unum)

Attachment: TEST.ZIP [ 12753 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

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.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Version: Jaybird 2.2.7 [ 10660 ]

Version: Jaybird 2.2.6 [ 10588 ]

Version: Jaybird 2.2.5 [ 10582 ]

Version: Jaybird 2.2.4 [ 10531 ]

Version: Jaybird 2.2.3 [ 10510 ]

Version: Jaybird 2.2.2 [ 10480 ]

Version: Jaybird 2.2.1 [ 10474 ]

Version: Jaybird 2.2 [ 10053 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

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\(\);

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Link: This issue is related to JDBC307 [ JDBC307 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Root cause seems to be JDBC307.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

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.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Rescheduled JDBC307 for 2.2.9; I will keep this ticket open and track it separately to improve test coverage.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Fix Version: Jaybird 2.2.9 [ 10691 ]

Fix Version: Jaybird 3.0 [ 10440 ]

@firebird-automations
Copy link
Author

Commented by: Attila Molnár (e_pluribus_unum)

Hi!

Using InputStream and ResultSet close() worked.

Thank You!

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Added extra tests to verify fix of JDBC307 also fixed this.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment