You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
COPY APIs leave the connection out of sync when the COPY command doesn't copy through the client #6694
BeginBinaryExport, BeginBinaryImport, BeginRawBinaryCopy, BeginTextExport and BeginTextImport throw the intended InvalidOperationException ("This API only supports import/export from the client …") when the server completes the COPY right away, e.g. for COPY t TO '/some/file' (NpgsqlBinaryExporter.cs:93-97, NpgsqlBinaryImporter.cs:102-106, NpgsqlRawCopyStream.cs:113-117; the text APIs use the raw stream, NpgsqlConnection.cs:1247-1250, 1313-1316). They don't read the ReadyForQuery that follows the CommandComplete, and their cleanup doesn't either (NpgsqlBinaryExporter.cs:489-493, 528, NpgsqlBinaryImporter.cs:532-535, NpgsqlRawCopyStream.cs:419, 453). So the next command on the connection reads that ReadyForQuery where it expects its own response. On PostgreSQL 18.6, SELECT 42 after the exception failed with "Received backend message ReadyForQuery while expecting ParseCompleteMessage", and the connection was broken; the same happened after Close and a reopen from the pool, which handed out the same physical connection. The imports did import.
awaitusingvarconn=awaitdataSource.OpenConnectionAsync();// needs the pg_write_server_files roleAssert.Throws<InvalidOperationException>(()=>conn.BeginBinaryExport("COPY (SELECT 1) TO '/tmp/x.bin' (FORMAT BINARY)"));awaitusingvarcmd=newNpgsqlCommand("SELECT 1",conn);cmd.ExecuteScalar();// fails: it reads the leftover ReadyForQuery first
The released 8.0.9, 9.0.5 and 10.0.3 behave the same way. The exception was added in 2017 for #1673 (2a5029e), where a user had passed COPY … FROM 'C:\temp\test.csv' to BeginTextImport.
Activity