typelevel / typelevel/doobie

Call next after implicit close of a result set

Open
#545 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
379
Avg merge
14m
Merged PRs (30d)
8

Description

With IBM JDBC driver I can read part of a result set without problems, but when the complete result set is read, following error occurs.

com.ibm.db2.jcc.am.SqlException: [jcc][t4][10120][10898][3.64.133] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null

The problem is explained in detail on stack overflow. On an IBM Support site the error is further explained, the driver closes the result set automatically after the last row has been retrieved. Apparently, after this close, another next operation is executed which causes this error. A JDBC trace confirms this behavior.

Trace containing the error after calling next on closed result set

[jcc][SystemMonitor:start] 
[jcc][Time:2017-07-12-15:18:17.793][Thread:main][ResultSet@aaee2a2]next () called
[jcc][Time:2017-07-12-15:18:17.793][Thread:main][ResultSet@aaee2a2]closeX (null, com.ibm.db2.jcc.uw.UWConnection@6f38a289) called
[jcc][Time:2017-07-12-15:18:17.793][Thread:main][ResultSet@aaee2a2]markClosed () called
[jcc][Time:2017-07-12-15:18:17.794][Thread:main][ResultSet@aaee2a2]next () returned false
[jcc][Thread:main][SystemMonitor:stop] core: 0.621309ms | network: 0.0ms | server: 0.0ms [STMT@687685057]
[jcc][SystemMonitor:start] 
[jcc][Time:2017-07-12-15:18:17.801][Thread:main][ResultSet@aaee2a2]next () called
[jcc][Time:2017-07-12-15:18:17.801][Thread:main][ResultSet@aaee2a2]checkForClosedResultSet () called
[jcc] BEGIN TRACE_DIAGNOSTICS
[jcc][Thread:main][Throwable@6f4ade6e] java.lang.Exception
[jcc][Thread:main][Throwable@6f4ade6e] Message = Closure of result set com.ibm.db2.jcc.t4.i@aaee2a2 occured at 2017-07-12 15:18:17.327

Trace after configuring the database to allow calling next on a closed result set.

[jcc][Time:2017-07-12-15:35:22.588][Thread:main][ResultSet@aaee2a2]next () called
[jcc][Time:2017-07-12-15:35:22.588][Thread:main][ResultSet@aaee2a2]closeX (null, com.ibm.db2.jcc.uw.UWConnection@6f38a289) called
[jcc][Time:2017-07-12-15:35:22.588][Thread:main][ResultSet@aaee2a2]markClosed () called
[jcc][Time:2017-07-12-15:35:22.589][Thread:main][ResultSet@aaee2a2]next () returned false
[jcc][Thread:main][SystemMonitor:stop] core: 1.096568ms | network: 0.0ms | server: 0.0ms [STMT@687685057]
[jcc][SystemMonitor:start] 
[jcc][Time:2017-07-12-15:35:22.602][Thread:main][ResultSet@aaee2a2]next () called
[jcc][Time:2017-07-12-15:35:22.602][Thread:main][ResultSet@aaee2a2]next () returned false
[jcc][Thread:main][SystemMonitor:stop] core: 0.249076ms | network: 0.0ms | server: 0.0ms [STMT@687685057]
[jcc][SystemMonitor:start] 
[jcc][Time:2017-07-12-15:35:22.605][Thread:main][ResultSet@aaee2a2]close () called
[jcc][Time:2017-07-12-15:35:22.605][Thread:main][ResultSet@aaee2a2]closeX (null, com.ibm.db2.jcc.uw.UWConnection@6f38a289) called
[jcc][Thread:main][SystemMonitor:stop] core: 0.22381299999999998ms | network: 0.0ms | server: 0.0ms [STMT@687685057]
[jcc][SystemMonitor:start] 
[jcc][Time:2017-07-12-15:35:22.607][Thread:main][PreparedStatement@28fd3dc1]close () called
[jcc][Thread:main][SystemMonitor:stop] core: 0.21986599999999998ms | network: 0.0ms | server: 0.0ms 
[jcc][SystemMonitor:start] 
[jcc][Time:2017-07-12-15:35:22.609][Thread:main][Connection@6f38a289]commit () called
[jcc][t4][time:2017-07-12-15:35:22.609][Thread:main][tracepoint:5][Request.flush]

The JDBC Specification in section in Section 15.2.5 Closing a Result Set Object, contains a note, that some drivers may implicitly close a result set. So I guess, after a result set has been implicitly closed, next should not be called again.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the streaming query with the IBM JDBC driver and compare the two traces included in the issue. Trace the result-set iteration path; done means a driver that implicitly closes the result set does not receive a second next call or raise ERRORCODE=-4470.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.