On Thu, 2009-04-09 at 12:59 -0400, Tom Lane wrote:
> Bruce Momjian <[email protected]> writes:
> > Where are we on this?
>
> Pretty much nowhere --- there's no proposed patch, and I don't think
> it's exactly trivial. Do you want to put it on TODO?
Here is a patch that does what I think Heikki was suggesting. If a
proper fix is non-trivial, then I assume there's some problem with my
patch, but I'll post it for the archives anyway.
I don't see any obvious protocol synchronization problem, and it looks
like DoingCommandRead protects against that in the case of SIGINT to a
backend. And in the case of SIGTERM to a backend, the connection will be
terminated anyway.
Regards,
Jeff Davis
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index c8223bf..c0d3622 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -487,6 +487,17 @@ static int
CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
{
int bytesread = 0;
+ bool old_ImmediateInterruptOK = ImmediateInterruptOK;
+
+ /*
+ * For the duration of CopyGetData, we want to allow immediate
+ * interrupts so that a shutdown can still occur even if the
+ * client stalls in the middle of a COPY. This won't affect query
+ * cancellation, because DoingCommandRead will still be true if in
+ * the middle of receiving a message, which is important to avoid
+ * protocol synchronization problems.
+ */
+ ImmediateInterruptOK = true;
switch (cstate->copy_dest)
{
@@ -542,6 +553,7 @@ CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
case 'c': /* CopyDone */
/* COPY IN correctly terminated by frontend */
cstate->fe_eof = true;
+ ImmediateInterruptOK = old_ImmediateInterruptOK;
return bytesread;
case 'f': /* CopyFail */
ereport(ERROR,
@@ -578,6 +590,8 @@ CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
break;
}
+ ImmediateInterruptOK = old_ImmediateInterruptOK;
+
return bytesread;
}
--
Sent via pgsql-bugs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs