From: | ljb <ljb220(at)mindspring(dot)com> |
---|---|
To: | pgsql-patches(at)postgresql(dot)org |
Subject: | libpq v2 protocol error: COPY FROM STDIN, PQputCopyEnd() |
Date: | 2004-03-09 01:45:39 |
Message-ID: | c2j7k3$2sus$1@news.hub.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
This fixes a protocol violation and disconnect when 7.4.x libpq is talking
to a v2 protocol (<=7.3.x) server. The client does COPY FROM STDIN, uses
the new call PQputCopyData(), then ends the copy using PQputCopyEnd(),
and gets back the odd message:
FATAL: Socket command type
followed by "server closed the connection unexpectedly..."
(This won't be seen with psql because it uses the older PQputline() and
PQendcopy() functions. But it breaks COPY into a 7.3 server with my new
Tcl interface pgtcl-ng.)
The problem is that PQputCopyEnd() in libpq sends the copy terminator "\\.\n"
with a trailing null byte. The 7.3.x server does not want the trailing
null there, so it takes it for a command byte. The actual error is
"Socket command type %c unknown" but the %c is '\0' so you lose the rest.
Here's a 1-line patch against 7.4.1 which has PQputCopyEnd() send the
terminator "\\.\n" without a trailing null. (Sorry I missed 7.4.2, but I
just found this.) It will also apply OK (with offset) to what I think will
be 7.4.2 (in CVS as fe-exec.c,v 1.153.2.3). Note this only affects the
down-level "v2" protocol code in libpq.
*** src/interfaces/libpq/fe-exec.c~ Sun Nov 30 15:53:43 2003
--- src/interfaces/libpq/fe-exec.c Mon Mar 8 19:16:37 2004
***************
*** 1447,1453 ****
{
/* Send old-style end-of-data marker */
if (pqPutMsgStart(0, false, conn) < 0 ||
! pqPuts("\\.\n", conn) < 0 ||
pqPutMsgEnd(conn) < 0)
return -1;
}
--- 1447,1453 ----
{
/* Send old-style end-of-data marker */
if (pqPutMsgStart(0, false, conn) < 0 ||
! pqPutnchar("\\.\n", 3, conn) < 0 ||
pqPutMsgEnd(conn) < 0)
return -1;
}
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2004-03-09 04:40:39 | Re: log_line_info |
Previous Message | Bruce Momjian | 2004-03-08 19:29:55 | Re: Alter table patch |