You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by John English <jo...@gmail.com> on 2012/11/03 12:15:09 UTC

40XD0: "Container has been closed"?

Suddenly for no discernable reason I'm getting this error (stacktrace 
below) while using getString() to read from a clob, the contents of 
which is only about 60K in length. I also have a testing interface which 
lets me type in raw SQL, and which also uses getString() to read the 
columns from the result set, and issuing the same query that producesd 
this error works fine from there.

The only thing I can think of that's different when it fails is that it 
is running in a background thread which waits for entries to appear in a 
work queue and then processes them. I can't see what difference that 
would make, though...

The Derby version is 10.8.1.2 (1095077) running on Java 1.7.0_03-b05.

Can anyone tell me why this might be happening please?

-------
java.sql.SQLException: An IOException was thrown when reading a 
'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
	at utils.Results.getString(Results.java:169)
	at utils.TestDetails.<init>(TestDetails.java:202)
	at utils.TestServer.run(TestServer.java:95)
Caused by: java.sql.SQLException: An IOException was thrown when reading 
a 'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)
	... 10 more
Caused by: java.sql.SQLException: Java exception: 'ERROR 40XD0: 
Container has been closed.: java.io.IOException'.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
	... 7 more
Caused by: java.io.IOException: ERROR 40XD0: Container has been closed.
	at 
org.apache.derby.impl.store.raw.data.OverflowInputStream.fillByteHolder(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream.read(Unknown 
Source)
	at java.io.DataInputStream.read(Unknown Source)
	at org.apache.derby.iapi.types.SQLClob.readExternal(Unknown Source)
	at org.apache.derby.iapi.types.SQLChar.getString(Unknown Source)
	... 5 more
Caused by: ERROR 40XD0: Container has been closed.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BaseContainerHandle.checkOpen(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BaseContainerHandle.getPage(Unknown 
Source)
	... 10 more
java.sql.SQLException: An IOException was thrown when reading a 
'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown Source)
	at utils.Results.getString(Results.java:169)
	at utils.TestDetails.<init>(TestDetails.java:183)
	at utils.TestServer.run(TestServer.java:95)
Caused by: java.sql.SQLException: An IOException was thrown when reading 
a 'java.lang.String' from an InputStream.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)
	... 10 more
Caused by: java.sql.SQLException: Java exception: 'ERROR 40XD0: 
Container has been closed.: java.io.IOException'.
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
Source)
	at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
Source)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
	at 
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
Source)
	... 7 more
Caused by: java.io.IOException: ERROR 40XD0: Container has been closed.
	at 
org.apache.derby.impl.store.raw.data.OverflowInputStream.fillByteHolder(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream.read(Unknown 
Source)
	at java.io.DataInputStream.read(Unknown Source)
	at org.apache.derby.iapi.types.SQLClob.readExternal(Unknown Source)
	at org.apache.derby.iapi.types.SQLChar.getString(Unknown Source)
	... 5 more
Caused by: ERROR 40XD0: Container has been closed.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BaseContainerHandle.checkOpen(Unknown 
Source)
	at 
org.apache.derby.impl.store.raw.data.BaseContainerHandle.getPage(Unknown 
Source)
	... 10 more

-- 
John English

Re: 40XD0: "Container has been closed"?

Posted by John English <jo...@gmail.com>.
On 03/11/2012 21:06, Katherine Marsden wrote:
> This has the feel of two threads using the same Connection and one
> commits or rolls back without coordination with the other. Typically
> each thread should have it's own connection.  Do you have a separate
> connection for each thread and if so, what is the isolation level?

No, each thread has its own connection. The situation is that tests can 
be run synchronously from a servlet, so a request comes in, a DB 
connection is created, the connection is used to do "select * from tests 
where id=?", and the results go back immediately in the response and the 
DB connection is then closed. Alternatively, tests can be scheduled to 
run asynchronously, and there is a thread created at system startup with 
its own connection which loops waiting for notifications that a test has 
completed and then issues exactly the same query.

In the synchronous case it always works; in the asynchronous case it 
always fails. I've tried creating a new connection each time round the 
loop in the asynchronous case, but it makes no difference. Also if it 
were a thread contention issue I'd expect to see some timing-dependent 
behaviour, not total consistency.

The rest of the row can always be read (ints and varchars and suchlike), 
but the clob always fails. I've tried reading the clob first; same 
thing. The isolation level is default, but in any case it happens even 
when nothing else is going on; I start an asynchronous test on my 
development rig with no other users, and then sit back and wait. It 
consistently hits the breakpoint I've set on the exception handler. This 
also points to it not being a thread contention problem.

One final thing: my "fix" (where I read the rest of the row in one query 
and the clob in another) uses the same connection for both queries.

So I'm totally baffled. Happy to have found a workaround but very 
annoyed that I don't understand why it works.

Thanks for your help,
-- 
John English

Re: 40XD0: "Container has been closed"?

Posted by Katherine Marsden <km...@sbcglobal.net>.
On 11/3/2012 4:15 AM, John English wrote:
> S
> -------
> java.sql.SQLException: An IOException was thrown when reading a 
> 'java.lang.String' from an InputStream.
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>     at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown 
> Source)
>     at utils.Results.getString(Results.java:169)
>     at utils.TestDetails.<init>(TestDetails.java:202)
>     at utils.TestServer.run(TestServer.java:95)
> Caused by: java.sql.SQLException: An IOException was thrown when 
> reading a 'java.lang.String' from an InputStream.
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
> Source)
>     ... 10 more
> Caused by: java.sql.SQLException: Java exception: 'ERROR 40XD0: 
> Container has been closed.: java.io.IOException'.
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>     at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>     ... 7 more
> Caused by: java.io.IOException: ERROR 40XD0: Container has been closed.
>     at 
> org.apache.derby.impl.store.raw.data.OverflowInputStream.fillByteHolder(Unknown 
> Source)
>     at 
> org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream.read(Unknown 
> Source)
>     at java.io.DataInputStream.read(Unknown Source)
>     at org.apache.derby.iapi.types.SQLClob.readExternal(Unknown Source)
>     at org.apache.derby.iapi.types.SQLChar.getString(Unknown Source)
>     ... 5 more
> Caused by: ERROR 40XD0: Container has been closed.
>     at 
> org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.store.raw.data.BaseContainerHandle.checkOpen(Unknown 
> Source)
>     at 
> org.apache.derby.impl.store.raw.data.BaseContainerHandle.getPage(Unknown 
> Source)
>     ... 10 more
> java.sql.SQLException: An IOException was thrown when reading a 
> 'java.lang.String' from an InputStream.
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>     at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.EmbedResultSet.noStateChangeException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.EmbedResultSet.getString(Unknown 
> Source)
>     at utils.Results.getString(Results.java:169)
>     at utils.TestDetails.<init>(TestDetails.java:183)
>     at utils.TestServer.run(TestServer.java:95)
> Caused by: java.sql.SQLException: An IOException was thrown when 
> reading a 'java.lang.String' from an InputStream.
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
> Source)
>     ... 10 more
> Caused by: java.sql.SQLException: Java exception: 'ERROR 40XD0: 
> Container has been closed.: java.io.IOException'.
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown 
> Source)
>     at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown 
> Source)
>     at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>     at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>     ... 7 more
> Caused by: java.io.IOException: ERROR 40XD0: Container has been closed.
>     at 
> org.apache.derby.impl.store.raw.data.OverflowInputStream.fillByteHolder(Unknown 
> Source)
>     at 
> org.apache.derby.impl.store.raw.data.BufferedByteHolderInputStream.read(Unknown 
> Source)
>     at java.io.DataInputStream.read(Unknown Source)
>     at org.apache.derby.iapi.types.SQLClob.readExternal(Unknown Source)
>     at org.apache.derby.iapi.types.SQLChar.getString(Unknown Source)
>     ... 5 more
> Caused by: ERROR 40XD0: Container has been closed.
>     at 
> org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>     at 
> org.apache.derby.impl.store.raw.data.BaseContainerHandle.checkOpen(Unknown 
> Source)
>     at 
> org.apache.derby.impl.store.raw.data.BaseContainerHandle.getPage(Unknown 
> Source)
>     ... 10 more
>
This has the feel of two threads using the same Connection and one 
commits or rolls back without coordination with the other. Typically 
each thread should have it's own connection.  Do you have a separate 
connection for each thread and if so, what is the isolation level?

Thanks

Kathey




Re: 40XD0: "Container has been closed"?

Posted by John English <jo...@gmail.com>.
On 03/11/2012 13:15, John English wrote:
> Suddenly for no discernable reason I'm getting this error (stacktrace
> below) while using getString() to read from a clob, the contents of
> which is only about 60K in length.

Something interesting: I've "fixed" the problem (i.e. made it go away). 
I'm always reading a single row with the query, so I've changed my code 
from:
   * execute the query
   * take all row elements and store them in variables
   * close the result set etc.
to
   * execute the query
   * take all row elements except the CLOB and store them in variables
   * close the result set etc.
   * execute the same query
   * take only the CLOB and store it in a variable
   * close the result set etc.
and that made the problem go away.

Naturally, I'm somewhat dissatisfied with this!
Any ideas welcomed...

TIA,
-- 
John English