BUG #17070: Sometimes copy from ingnores transaction

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: d(dot)sekretov(at)gmail(dot)com
Subject: BUG #17070: Sometimes copy from ingnores transaction
Date: 2021-06-23 07:02:18
Message-ID: 17070-701777d014fe5684@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17070
Logged by: Дмитрий Секретов
Email address: d(dot)sekretov(at)gmail(dot)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?

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Heikki Linnakangas 2021-06-23 07:45:58 Re: BUG #17064: Parallel VACUUM operations cause the error "global/pg_filenode.map contains incorrect checksum"
Previous Message Vladimir Shvartsgor 2021-06-23 06:40:32 Example in "42.8. Transaction Management" doesn't work for PostgreSQL v 12.7