Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 87E402E3304 for ; Thu, 13 Dec 2007 15:10:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 75870-01 for ; Thu, 13 Dec 2007 15:09:43 -0400 (AST) Received: from web39104.mail.mud.yahoo.com (web39104.mail.mud.yahoo.com [209.191.87.32]) by postgresql.org (Postfix) with SMTP id 87E5A2E3AA9 for ; Thu, 13 Dec 2007 15:09:50 -0400 (AST) Received: (qmail 58355 invoked by uid 60001); 13 Dec 2007 19:09:49 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=dKVc7Fv2hPT4qRd3dfUK7eFjnLqsuJ4CIHOKd1gP40kVlbXm18smEsah++ren35DaNhbOekwpzMwZIiRhomRAbGyes6cM+gXC3gxcKVMpqm0PNztbE2lTouq+GVQGFHZ/BUp/8wi+aYQLok5YQFR43yspLpuKSrNyjPuy0cBpyY=; X-YMail-OSG: Ea32KrMVM1lWavbxR1mvUf7GNE0kIZYpHBWUz4ncrW_qn.9LBcHyoQArbgcd.nSwLnYoZ8RxDZtB5VPapmH_yxguCwJuUqJeUvGbye7sgawB1jQ- Received: from [210.2.161.149] by web39104.mail.mud.yahoo.com via HTTP; Thu, 13 Dec 2007 11:09:49 PST Date: Thu, 13 Dec 2007 11:09:49 -0800 (PST) From: Altaf Malik Subject: Re: JDBC causing the connection to close after executing a COPY command To: Kris Jurka Cc: Dave Cramer , pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-2077317115-1197572989=:58043" Content-Transfer-Encoding: 8bit Message-ID: <35579.58043.qm@web39104.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/91 X-Sequence-Number: 17946 --0-2077317115-1197572989=:58043 Content-Type: multipart/alternative; boundary="0-1636175336-1197572989=:58043" --0-1636175336-1197572989=:58043 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I debugged little more and found that this is not because of incomplete copy support. When a response to any of the copy operations is received, JDBC reads next few bytes to ignore the response. But unfortunately driver reads extra four bytes which is the RFQ message so the RFQ message gets corrupted and IOException is thrown considering it as an unknown packet. I am attaching a patch that fixes this issue and driver works smoothly even after giving the error on copy response. Regards, Altaf Malik EnterpriseDB http://www.enterprisedb.com/ Kris Jurka wrote: On Thu, 13 Dec 2007, Altaf Malik wrote: > Also if i enable logging in JDBC, and only execute the COPY statement, > log shows that FrontEnd sent a Terminate message. > What's happening is that after receiving the server's message that it wants to do a COPY, the driver doesn't understand the protocol and dies with an "java.io.IOException: Unexpected packet type: " error. Once this happens the driver can't do anything but close the connection. As part of the connection closing process it issues a Terminate message to the server, in case it's still listening and the protocol is in a good enough state that the server might receive it. The driver is not explicitly terminating the connection upon receiving a copy request, that's just what happens when it gets confused. Kris Jurka --------------------------------- Never miss a thing. Make Yahoo your homepage. --0-1636175336-1197572989=:58043 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I debugged little more and found that this is not because of incomplete copy support. When a response to any of the copy operations is received, JDBC reads next few bytes to ignore the response. But unfortunately driver reads extra four bytes which is the RFQ message so the RFQ message gets corrupted and IOException is thrown considering it as an unknown packet.

I am attaching a patch that fixes this issue and driver works smoothly even after giving the error on copy response.

Regards,
Altaf Malik
EnterpriseDB
http://www.enterprisedb.com/

Kris Jurka <books@ejurka.com> wrote:


On Thu, 13 Dec 2007, Altaf Malik wrote:

> Also if i enable logging in JDBC, and only execute the COPY statement,
> log shows that FrontEnd sent a Terminate message.
>

What's happening is that after receiving the server's message that it
wants to do a COPY, the driver doesn't understand the protocol and dies
with an "java.io.IOException: Unexpected packet type: " error. Once this
happens the driver can't do anything but close the connection. As part of
the connection closing process it issues a Terminate message to the
server, in case it's still listening and the protocol is in a good enough
state that the server might receive it. The driver is not explicitly
terminating the connection upon receiving a copy request, that's just what
happens when it gets confused.

Kris Jurka


Never miss a thing. Make Yahoo your homepage. --0-1636175336-1197572989=:58043-- --0-2077317115-1197572989=:58043 Content-Type: text/x-patch; name="pg_copy.diff" Content-Description: 2290331491-pg_copy.diff Content-Disposition: inline; filename="pg_copy.diff" *** org/postgresql/core/v3/QueryExecutorImpl.java 2007-10-15 13:06:24.000000000 +0500 --- org/postgresql/core/v3/QueryExecutorImpl.java 2007-12-13 20:37:28.000000000 +0500 *************** *** 1439,1445 **** int l_len = pgStream.ReceiveInteger4(); /* discard */ ! pgStream.Receive(l_len); handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED)); } --- 1439,1446 ---- int l_len = pgStream.ReceiveInteger4(); /* discard */ ! // read l_len-4 (length includes the 4 bytes for message length itself ! pgStream.Receive(l_len - 4); handler.handleError(new PSQLException(GT.tr("The driver currently does not support COPY operations."), PSQLState.NOT_IMPLEMENTED)); } --0-2077317115-1197572989=:58043--