pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: d.sekretov@gmail.com
Subject: BUG #17070: Sometimes copy from ingnores transaction
Date: Wed, 23 Jun 2021 07:02:18 +0000
Message-ID: <17070-701777d014fe5684@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17070
Logged by:          Дмитрий Секретов
Email address:      d.sekretov@gmail.com
PostgreSQL version: 12.1
Operating system:   Windows Server 2016
Description:        

Driver: Npgsql 4.0.9 (.net 4.7.1)

We use following construction in our code:
1. Start transaction
2. COPY FROM STDIN BINARY (table name depends on context)
3. Insert into "some_table"("some_value")
4. Commit transaction

It works fine. When something goes wrong then transaction rollbacks. 
But we found the issue. We do copy operation (step 2). When copy commands
ended the driver sends “copy done” command to postgresql backed and starts
waiting for “command complete” message and error occurs during waiting. 

2021-04-29 02:40:01,593 ERROR Exception while reading from stream --->
System.IO.IOException: Unable to read data from the transport connection: A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond. 

In a 160 seconds postgresql reported in logs

2021-04-29 02:42:41 database LOG:  duration: 202590.129 ms  statement: COPY
"principal_reference" (id,"some_payload") FROM STDIN BINARY;
2021-04-29 02:42:41 database LOG:  could not receive data from client: An
established connection was aborted by the software in your host machine.

In our application code we retry operation, if something goes wrong. And
when we start retrying we've got an exception
2021-04-29 02:42:41 database ERROR:  duplicate key value violates unique
constraint "PK_principal_reference_id"

We didn't commit transaction. But copy done successfully and there is no row
inserted at step 3. 
Is there a workaround? Like a copy into temp table and then insert from temp
table?



view thread (4+ messages)  latest in thread

Message-ID: <17070-701777d014fe5684@postgresql.org>
Permalink:  ../17070-701777d014fe5684@postgresql.org/
Also on:    postgresql.org/message-id/17070-701777d014fe5684@postgresql.org

 · 

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: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, d.sekretov@gmail.com
  Subject: Re: BUG #17070: Sometimes copy from ingnores transaction
  In-Reply-To: <17070-701777d014fe5684@postgresql.org>

* 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