Menu

#572 TDS Protocol error: Invalid packet type 0xc9

v2.x
closed
nobody
7
2012-08-15
2008-08-14
No

This happens when 2 ResultSets on the same connection are being iterated at the same time. Setting useCursors=true fixes the problem, but we don't want the performance penalty of server side cursors.
Below is the exception, but even more disturbing is that even when the exception is not generated, bad data is sometimes returned!

java.sql.SQLException: TDS Protocol error: Invalid packet type 0xc9
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2316)
at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:764)
at net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:593)
at com.knoa.commons.sql.SQLHelper.diff(SQLHelper.java:397)
at com.knoa.commons.sql.SQLHelper.diff(SQLHelper.java:362)
at com.knoa.validation.AnalysisSanity.diff(AnalysisSanity.java:298)
at com.knoa.validation.AnalysisSanity.diffRdtError(AnalysisSanity.java:341)
at com.knoa.test.ServerTest.rdtError(ServerTest.java:769)
at com.knoa.analysis.service.agg.RelabelServiceTest.rdtError(RelabelServiceTest.java:111)
Caused by: net.sourceforge.jtds.jdbc.ProtocolException: Invalid packet type 0xc9
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2303)
... 30 more
... Removed 22 stack frames

Discussion

  • momo

    momo - 2009-07-29

    Thank you for reporting that issue. I created a simple test (see below) but was not able to reproduce the problem here. Does this test work in your setup? Could you provide further details or adapt the test to show the error?

    /**
    
     * Test for bug [2051585], TDS Protocol error when 2 ResultSets on the
     * same connection are being iterated at the same time.
     */
    public void testConcurrentResultSets() throws Exception {
        con.setAutoCommit(false);
    
        final int rows    = 100000;
        final int threads = 2;
    
        final Thread[] workers = new Thread[threads];
        final List     errors  = new ArrayList();
    
        for (int i=0; i < threads; i++) {
            // create and fill a separate table per thread
            System.out.println("preparing thread " + i);
            Statement stmt = con.createStatement();
            stmt.execute("create table #conrs"+i+" (id int,data varchar(20))");
            for (int r=0; r < rows; r++) {
                assertEquals(1, stmt.executeUpdate("insert into #conrs"+i+" values(" + r + ",'test" + r + "')"));
            }
            stmt.close();
            con.commit();
    
            final int c = i;
            workers[i] = new Thread("thread " + i) {
                public void run() {
                    try {
                        Statement st = con.createStatement();
                        ResultSet rs = st.executeQuery("select * from #conrs" + c + " order by id asc");
    
                        for (int i=0; i < rows; i++) {
                            assertTrue(rs.next());
                            assertEquals(i, rs.getInt(1));
                            assertEquals("test" + i, rs.getString(2));
                        }
    
                        rs.close();
                        st.close();
                    }
                    catch (Throwable t) {
                        synchronized (errors) {
                            errors.add(new Exception(this.getName() + ": " + t.getMessage(),t));
                        }
                    }
                }
            };
        }
    
        System.out.println("inserts complete");
    
        // start all threads
        for (int i=0; i < threads; i++) {
            workers[i].start();
        }
    
        System.out.println("threads are running");
    
        // wait for the threads to finish
        for (int i=0; i < threads; i++) {
            workers[i].join();
        }
    
        assertEquals(Arrays.toString(errors.toArray()), "[]");
    
        con.setAutoCommit(true);
    }
    
     
  • momo

    momo - 2009-07-29

    I run the test against the current jTDS 2.0 code base and that indeed caused errors. I still haven't seen the "Invalid packet type 0xc9" message but the results are mixed up (maybe that's what you called "bad data") between the different threads. Are you using a jTDS version compiled from CVS?

     
  • momo

    momo - 2009-07-29

    Please forget my last question, the stacktrace is answer enough...

     
  • momo

    momo - 2009-08-04

    I assigned the bug to jTDS v2. If anyone is able to reproduce the problem with jTDS 1.2.2, please drop me a line.

     
  • momo

    momo - 2009-12-07

    I'm closing this bug due to jTDS 2.0 being too far from production ready. We have a unit test showing this problem and version 2 will not make it into a release before all tests succeed, anyway.

    Cheers,
    momo

     

Log in to post a comment.

MongoDB Logo MongoDB