Re: [bug fix] psql \copy doesn't end if backend is killed - Mailing list pgsql-hackers

From Dilip kumar
Subject Re: [bug fix] psql \copy doesn't end if backend is killed
Date
Msg-id 4205E661176A124FAF891E0A6BA91352659435A2@SZXEML507-MBS.china.huawei.com
Whole thread Raw
In response to [bug fix] psql \copy doesn't end if backend is killed  ("MauMau" <maumau307@gmail.com>)
Responses Re: [bug fix] psql \copy doesn't end if backend is killed
List 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
stepsexplained. 
1. Make pqsecure_write to return less byte(by updating the result while debugging in gdb  in pqSendSome.(also make sure
thatremaining byte is >= 8192 i.e conn->outCount-sent > 8192 , so that in next step pqPutMsgEnd called from
PQputCopyEndgo 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





pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: WIP patch (v2) for updatable security barrier views
Next
From: Craig Ringer
Date:
Subject: Re: WIP patch (v2) for updatable security barrier views