pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
Cc: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Cc: thomas.munro@enterprisedb.com
Cc: eric.cyr@gmail.com
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: BUG #15449: file_fdw using program cause exit code error when using LIMIT
Date: Fri, 16 Nov 2018 12:33:51 -0500
Message-ID: <31355.1542389631@sss.pgh.pa.us> (raw)
In-Reply-To: <30744.1542388851@sss.pgh.pa.us>
References: <5BE4318F.4040002@lab.ntt.co.jp>
	<20181109.143931.243136889.horiguchi.kyotaro@lab.ntt.co.jp>
	<5BE552ED.4040304@lab.ntt.co.jp>
	<20181112.185214.76711162.horiguchi.kyotaro@lab.ntt.co.jp>
	<5BE966F4.1040702@lab.ntt.co.jp>
	<5BEA9E82.1080709@lab.ntt.co.jp>
	<30744.1542388851@sss.pgh.pa.us>

I wrote:
> Are we sufficiently convinced that we must have the dont-allow-partial
> option to not fix this in the back branches?  I'm not.

I just had a thought about that: suppose we add a flag to CopyState
to indicate whether we reached EOF while reading.  This wouldn't be
hugely expensive, just something like

    switch (cstate->copy_dest)
    {
        case COPY_FILE:
            bytesread = fread(databuf, 1, maxread, cstate->copy_file);
            if (ferror(cstate->copy_file))
                ereport(ERROR,
                        (errcode_for_file_access(),
                         errmsg("could not read from COPY file: %m")));
+           cstate->reached_eof |= (bytesread < maxread);
            break;
        case COPY_OLD_FE:

Then the logic in ClosePipeToProgram could be "if we did not reach
EOF, then a SIGPIPE termination is unsurprising.  If we did reach
EOF, then SIGPIPE is an error."  If the called program gets SIGPIPE
for some reason other than us closing the pipe early, then we would
see EOF next time we try to read, and correctly report that there's
a problem.

There are race-ish conditions in cases like the called program
getting an unrelated SIGPIPE at about the same time that we decide
to stop reading early, but I don't think it's really possible
to disambiguate that.

			regards, tom lane




view thread (28+ messages)  latest in thread

Message-ID: <31355.1542389631@sss.pgh.pa.us>
Permalink:  ../31355.1542389631@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/31355.1542389631@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fujita.etsuro@lab.ntt.co.jp, horiguchi.kyotaro@lab.ntt.co.jp, thomas.munro@enterprisedb.com, eric.cyr@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: BUG #15449: file_fdw using program cause exit code error when using LIMIT
  In-Reply-To: <31355.1542389631@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox