Re: [GENERAL] \copy: unexpected response (4)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [GENERAL] \copy: unexpected response (4)
Дата
Msg-id 24444.1249666439@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: [GENERAL] \copy: unexpected response (4)  (Neil Best <nbest@ci.uchicago.edu>)
Список pgsql-hackers
I wrote:
> Hmm, so it looks like the connection dropped and libpq failed to
> recognize that, or maybe libpq was okay but psql needs to check a bit
> more carefully here.  I'll take a look.

I could not reproduce this problem in testing, but after eyeballing
the code awhile I have a theory.  It looks like it is possible for
PQputCopyEnd to fail and leave the PGconn in COPY_IN state, but this
only happens (1) if the output buffer contained at least 8K already,
causing pqSendSome to be invoked from pqPutMsgEnd, and (2) pqSendSome
returned failure.  In that situation the loop in copy.c becomes
infinite, since there's no mechanism for getting out of COPY_IN state.
This case would be relatively difficult to trigger, but it seems to fit
all the facts, if we assume that the connection had failed for some
reason just at that point.  BTW, the "SSL renegotiation failure" bit
suggests that it could have been an OpenSSL bug not a real network
lossage, so you might want to see how up-to-date your openssl libraries
are.

Anyway, it seems to me that the most appropriate fix is to add some
code to that loop, along the lines of

    /*
     * Make sure we have pumped libpq dry of results; else it may still be in
     * ASYNC_BUSY state, leading to false readings in, eg, get_prompt().
     */
    while ((result = PQgetResult(pset.db)) != NULL)
    {
        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(conn, _("trying to exit copy mode"));
        PQclear(result);
    }

This would cover this particular case and perhaps others as well.

            regards, tom lane

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: mixed, named notation support
Следующее
От: Sam Mason
Дата:
Сообщение: Re: Fixing geometic calculation