Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 4781DB5FC2D for ; Wed, 1 Jun 2011 10:44:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 83229-01 for ; Wed, 1 Jun 2011 13:44:01 +0000 (UTC) X-Greylist: delayed 00:37:07.003215 by SQLgrey-1.7.6 Received: from Amber.meep.pl (unknown [193.23.174.18]) by mail.postgresql.org (Postfix) with ESMTP id 26FFFB5DCA1 for ; Wed, 1 Jun 2011 10:44:01 -0300 (ADT) Received: from mike by Amber.meep.pl with local (Exim 4.76) (envelope-from ) id 1QRl8L-0006X2-VK for pgsql-general@postgresql.org; Wed, 01 Jun 2011 15:06:49 +0200 Date: Wed, 1 Jun 2011 15:06:49 +0200 From: Michal Politowski To: pgsql-general@postgresql.org Subject: Mixed up protocol packets in server response? Message-ID: <20110601130649.GA21333@meep.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-PGP: 1024D/EDBBB56F; A690 41A9 6DDE 7496 6A72 C51B 7DEE 64EB EDBB B56F; 2006-04-21 -- 2009-08-12 User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.342 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_BRBL_LASTEXT=1.449, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201106/11 X-Sequence-Number: 176444 I have an instance of what looks like a weird mixup of data returned by the= server. This is observed in a Java application using the 9.0-801.jdbc4 JDBC driver= =20 connecting to an 8.3.4 server (yes, it's old) running on Solaris. The application hung waiting for the result of one select * from a_table where a_field =3D parameter; Looking at it with a debugger I see that: 1. it waits in: SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line:= not available [native method]=09 SocketInputStream.read(byte[], int, int) line: 129=09 VisibleBufferedInputStream.read(byte[], int, int) line: 219=09 PGStream.Receive(byte[], int, int) line: 460=09 PGStream.ReceiveTupleV3() line: 365=09 QueryExecutorImpl.processResults(ResultHandler, int) line: 1814=09 QueryExecutorImpl.execute(Query, ParameterList, ResultHandler, int, int, i= nt) line: 257=09 Jdbc4PreparedStatement(AbstractJdbc2Statement).execute(Query, ParameterLis= t, int) line: 500=09 Jdbc4PreparedStatement(AbstractJdbc2Statement).executeWithFlags(int) line:= 388=09 Jdbc4PreparedStatement(AbstractJdbc2Statement).executeQuery() line: 273=09 because it expects a field of size =3D 825767394 (l_size in ReceiveTupleV3) which is much more than the whole result should be. 2. then looking at the answer array in ReceiveTupleV3: A few first fields have the expected values, then answer[3] has the expected size but somewhere in the middle it changes from field 3 of the first row of the result to the middle of field 3 of the last row of the result. Then of course there are 4 bytes of this field that as a 32-bit integer have the value of 825767394. Then answer[4] obviously has 825767394 elements. And it continues with the field 3 of the last row and then it contains the 4-byte length and then value of the field 4 (last) of the last row of the result - so the end of a DataRow message. Then a CommandComplete message with the tag "SELECT", then a ReadyForQuery message with the status indicator "T". And then there is the rest of the field 3 of the first row, then length and value for the field 4 of the first row and then the DataRow messages for the following rows of the result. The last one up until the place where=20 it got mixed up before. So it looks like the server wanted to send D row 1, D row 2, D row 3, D row 4, C SELECT, Z T but the application sees D ro, ow 4, C SELECT, Z T, w 1, D row 2, D row 3, D r What may be the cause of this weird problem? Is it some known or unknown bu= g in 8.3.4 or is the application/Java side more suspected? --=20 Micha=B3 Politowski Talking has been known to lead to communication if practiced carelessly.