You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Rick Hillegas (JIRA)" <ji...@apache.org> on 2010/11/18 20:30:14 UTC

[jira] Updated: (DERBY-4315) Attempt to reuse streams in client on insert gives protocol exception and inserts wrong data

     [ https://issues.apache.org/jira/browse/DERBY-4315?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Hillegas updated DERBY-4315:
---------------------------------

    Attachment: ReproReuseStream.java

Attaching a revised version of the repro. This version runs the test on both the embedded and client/server drivers. To run this version, you need to specify the port which the server is listening on:

java ReproReuseStream 8246

########################################################
#
#	jdbc:derby:memory:db1;create=true
#
########################################################

Drop exception ok:'DROP TABLE' cannot be performed on 'TEST' because it does not exist.
Insert row 1 
Try to insert row 2 with reused streams 
Caught SQLException. SQLState = XSDA4
An unexpected exception was thrown
java.sql.SQLException: An unexpected exception was thrown
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:95)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:142)
	at org.apache.derby.impl.jdbc.Util.seeNextException(Util.java:278)
	at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:403)
	at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(TransactionResourceImpl.java:348)
	at org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConnection.java:2284)
	at org.apache.derby.impl.jdbc.ConnectionChild.handleException(ConnectionChild.java:82)
	at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1333)
	at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(EmbedPreparedStatement.java:1686)
	at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(EmbedPreparedStatement.java:308)
	at ReproReuseStream.execute(ReproReuseStream.java:64)
	at ReproReuseStream.main(ReproReuseStream.java:27)
Caused by: java.sql.SQLException: An unexpected exception was thrown
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:45)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory40.java:119)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:70)
	... 11 more
Caused by: java.sql.SQLException: Java exception: 'Stream has already been read and end-of-file reached and cannot be re-used.: java.io.EOFException'.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:45)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory40.java:119)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:70)
	at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:142)
	at org.apache.derby.impl.jdbc.Util.javaException(Util.java:299)
	at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(TransactionResourceImpl.java:408)
	... 9 more
Caused by: java.io.EOFException: Stream has already been read and end-of-file reached and cannot be re-used.
	at org.apache.derby.iapi.types.RawToBinaryFormatStream.read(RawToBinaryFormatStream.java:254)
	at org.apache.derby.impl.store.raw.data.MemByteHolder.write(MemByteHolder.java:146)
	at org.apache.derby.impl.store.raw.data.RememberBytesInputStream.fillBuf(RememberBytesInputStream.java:135)
	at org.apache.derby.impl.store.raw.data.StoredPage.logColumn(StoredPage.java:6197)
	at org.apache.derby.impl.store.raw.data.StoredPage.logRow(StoredPage.java:3972)
	at org.apache.derby.impl.store.raw.data.InsertOperation.writeOptionalDataToBuffer(InsertOperation.java:370)
	at org.apache.derby.impl.store.raw.data.InsertOperation.<init>(InsertOperation.java:115)
	at org.apache.derby.impl.store.raw.data.LoggableActions.actionInsert(LoggableActions.java:139)
	at org.apache.derby.impl.store.raw.data.BasePage.insertNoOverflow(BasePage.java:602)
	at org.apache.derby.impl.store.raw.data.BasePage.insertAtSlot(BasePage.java:523)
	at org.apache.derby.impl.store.raw.data.StoredPage.insertAtSlot(StoredPage.java:6771)
	at org.apache.derby.impl.store.raw.data.BasePage.insert(BasePage.java:629)
	at org.apache.derby.impl.store.access.heap.HeapController.doInsert(HeapController.java:255)
	at org.apache.derby.impl.store.access.heap.HeapController.insertAndFetchLocation(HeapController.java:599)
	at org.apache.derby.impl.sql.execute.RowChangerImpl.insertRow(RowChangerImpl.java:452)
	at org.apache.derby.impl.sql.execute.InsertResultSet.normalInsertCore(InsertResultSet.java:1028)
	at org.apache.derby.impl.sql.execute.InsertResultSet.open(InsertResultSet.java:505)
	at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(GenericPreparedStatement.java:436)
	at org.apache.derby.impl.sql.GenericPreparedStatement.execute(GenericPreparedStatement.java:317)
	at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(EmbedStatement.java:1241)
	... 4 more
Go ahead and commit so we can see the wrong data.
ID         |MNAME                                                                                                                           |MVALUE     |BYTEDATA                                                                                                                        |CHARDATA                                                                                                                        
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1          |mname                                                                                                                           |0          |6363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636&|ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc&

########################################################
#
#	jdbc:derby://localhost:8246/memory:db2;create=true
#
########################################################

Insert row 1 
Try to insert row 2 with reused streams 
Caught SQLException. SQLState = XN017
Network protocol error: end of stream prematurely reached, parameter #4.  Remaining data has been padded with 0x0.
java.sql.SQLException: Network protocol error: end of stream prematurely reached, parameter #4.  Remaining data has been padded with 0x0.
	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:96)
	at org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:358)
	at org.apache.derby.client.am.PreparedStatement.executeUpdate(PreparedStatement.java:403)
	at ReproReuseStream.execute(ReproReuseStream.java:64)
	at ReproReuseStream.main(ReproReuseStream.java:28)
Caused by: org.apache.derby.client.am.SqlException: Network protocol error: end of stream prematurely reached, parameter #4.  Remaining data has been padded with 0x0.
	at org.apache.derby.client.net.Request.writePlainScalarStream(Request.java:339)
	at org.apache.derby.client.net.Request.writeScalarStream(Request.java:247)
	at org.apache.derby.client.net.NetStatementRequest.buildEXTDTA(NetStatementRequest.java:983)
	at org.apache.derby.client.net.NetStatementRequest.writeExecute(NetStatementRequest.java:152)
	at org.apache.derby.client.net.NetPreparedStatement.writeExecute_(NetPreparedStatement.java:178)
	at org.apache.derby.client.am.PreparedStatement.writeExecute(PreparedStatement.java:1791)
	at org.apache.derby.client.am.PreparedStatement.flowExecute(PreparedStatement.java:2021)
	at org.apache.derby.client.am.PreparedStatement.executeUpdateX(PreparedStatement.java:408)
	at org.apache.derby.client.am.PreparedStatement.executeUpdate(PreparedStatement.java:394)
	... 2 more
Go ahead and commit so we can see the wrong data.
ID         |MNAME                                                                                                                           |MVALUE     |BYTEDATA                                                                                                                        |CHARDATA                                                                                                                        
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1          |mname                                                                                                                           |0          |6363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636&|ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc&


> Attempt to reuse streams in client on insert gives protocol exception and inserts wrong data
> --------------------------------------------------------------------------------------------
>
>                 Key: DERBY-4315
>                 URL: https://issues.apache.org/jira/browse/DERBY-4315
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.1.3.1, 10.2.2.0, 10.3.3.0, 10.4.2.0, 10.5.1.1, 10.5.2.0, 10.6.1.0
>            Reporter: Kathey Marsden
>         Attachments: ReproReuseStream.java, ReproReuseStream.java
>
>
> If a user attempts to reuse a stream set as a parameter to a prepared statement, the statement execution should fail with SQL State XJ001.  Instead client fails with a protocol error and inserts wrong data. See the attached java program ReproReuseStream.java for a reproduction.
> [C:/kmarsden/repro/reusestream] java ReproReuseStream
> Insert row 1
> Try to insert row 2 with reused streams
> java.sql.SQLException: Network protocol error: end of stream prematurely reached, parameter #4.  Remaining data has been
>  padded with 0x0.
>         at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:96)
>         at org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:358)
>         at org.apache.derby.client.am.PreparedStatement.executeUpdate(PreparedStatement.java:399)
>         at ReproReuseStream.main(ReproReuseStream.java:41)
> Caused by: org.apache.derby.client.am.SqlException: Network protocol error: end of stream prematurely reached, parameter
>  #4.  Remaining data has been padded with 0x0.
>         at org.apache.derby.client.net.Request.writePlainScalarStream(Request.java:490)
>         at org.apache.derby.client.net.Request.writeScalarStream(Request.java:264)
>         at org.apache.derby.client.net.NetStatementRequest.buildEXTDTA(NetStatementRequest.java:951)
>         at org.apache.derby.client.net.NetStatementRequest.writeExecute(NetStatementRequest.java:147)
>         at org.apache.derby.client.net.NetPreparedStatement.writeExecute_(NetPreparedStatement.java:178)
>         at org.apache.derby.client.am.PreparedStatement.writeExecute(PreparedStatement.java:1801)
>         at org.apache.derby.client.am.PreparedStatement.flowExecute(PreparedStatement.java:2031)
>         at org.apache.derby.client.am.PreparedStatement.executeUpdateX(PreparedStatement.java:404)
>         at org.apache.derby.client.am.PreparedStatement.executeUpdate(PreparedStatement.java:390)
>         ... 1 more
> Go ahead and commit so we can see the wrong data.
> ID         |MNAME
>                     |MVALUE     |BYTEDATA
>                                          |CHARDATA
> ------------------------------------------------------------------------------------------------------------------------
> ------------------------------------------------------------------------------------------------------------------------
> ------------------------------------------------------------------------------------------------------------------------
> --------------------------------------------------
> 1          |mname
>                     |0          |636363636363636363636363636363636363636363636363636363636363636363636363636363636363636
> 3636363636363636363636363636363636363636&|cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
> ccccccccccccccccccccccccccccccccccccccccccccccccc&
> 2          |mname
>                     |0          |000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000&|
>                                                  &
> To workaround the issue users should not attempt to reuse streams but we should give a better message and not insert wrong data.
> The code was extracted from StreamingColumnTest testDerby500 but the commits were removed.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.