Re: [bug fix] psql \copy doesn't end if backend is killed

From: Dilip kumar <dilip(dot)kumar(at)huawei(dot)com>
To: MauMau <maumau307(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [bug fix] psql \copy doesn't end if backend is killed
Date: 2014-01-31 09:17:02
Message-ID: 4205E661176A124FAF891E0A6BA91352659435A2@SZXEML507-MBS.china.huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 20 December 2013 19:43, MauMau Wrote

> [Problem]
> If the backend is terminated with SIGKILL while psql is running "\copy
> table_name from file_name", the \copy didn't end forever. I expected
> \copy
> to be cancelled because the corresponding server process vanished.
>
>
> [Cause]
> psql could not get out of the loop below in handleCopyIn():
>
> while (res = PQgetResult(conn), PQresultStatus(res) == PGRES_COPY_IN)
> {
> OK = false;
> PQclear(res);
>
> PQputCopyEnd(pset.db, _("trying to exit copy mode"));
> }

1. Patch applied to git head successfully
2. Problem can occur in some scenario and fix looks fine to me.
3. For testing, I think it's not possible to directly generate such scenario, so I have verified by debugging as the steps explained.

1. Make pqsecure_write to return less byte(by updating the result while debugging in gdb in pqSendSome.
(also make sure that remaining byte is >= 8192 i.e conn->outCount-sent > 8192 , so that in next step pqPutMsgEnd called from PQputCopyEnd go for flushing the data)

2. Then Kill the backend process before it calls pqReadData.

Scenario reproduced without patch and after applying the patch issue resolves.

Is there any direct scenario by which it can be reproduce ?

Regards,
Dilip



In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2014-01-31 09:30:28 Re: WIP patch (v2) for updatable security barrier views
Previous Message Dean Rasheed 2014-01-31 09:09:29 Re: WIP patch (v2) for updatable security barrier views