Try to defend against the possibility that libpq is still in COPY_IN state
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Aug 2009 20:16:11 +0000 (20:16 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 7 Aug 2009 20:16:11 +0000 (20:16 +0000)
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

index 2c88520b877de393475877a8d9d3c9d86b16c0bc..97a1cb1c44dfbf7b717b488c8df6e11aa49760f3 100644 (file)
@@ -571,6 +571,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);
        }