From b09e8b06670f84806a0102f25c1249e537398b1c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 7 Aug 2009 20:16:29 +0000 Subject: [PATCH] Try to defend against the possibility that libpq is still in COPY_IN state when we reach the post-COPY "pump it dry" error recovery code that was added 2006-11-24. Per a report from Neil Best, there is at least one code path in which this occurs, leading to an infinite loop in code that's supposed to be making it more robust not less so. A reasonable response seems to be to call PQputCopyEnd() again, so let's try that. Back-patch to all versions that contain the cleanup loop. --- src/bin/psql/copy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index f43ce258c3d..d77d99ad4ce 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.71.2.1 2007/02/05 15:23:24 adunstan Exp $ + * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.71.2.2 2009/08/07 20:16:29 tgl Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -603,6 +603,9 @@ do_copy(const char *args) success = false; psql_error("\\copy: unexpected response (%d)\n", PQresultStatus(result)); + /* if still in COPY IN state, try to get out of it */ + if (PQresultStatus(result) == PGRES_COPY_IN) + PQputCopyEnd(pset.db, _("trying to exit copy mode")); PQclear(result); }