mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-19 08:39:44 +00:00
PostgreSQL Bugfix: Ensure connection is usable after failed COPY inside a transaction (#3138)
* Include test case for regular subtransactions
While using COPY and subtransactions I kept running into errors.
This test case documents that error, it currently fails with:
Error: encountered unexpected or invalid data: expecting ParseComplete but received CommandComplete
* PostgreSQL Copy: Consume ReadyForQuery on error
When a COPY statement was in error inside a subtransaction,
a Protocol Error used to be raised. By consuming the ReadyForQuery
message when there is an error, we no longer have this issue.
This commit is contained in:
committed by
GitHub
parent
e42ee35a76
commit
17d832b3de
@@ -342,16 +342,21 @@ async fn pg_begin_copy_out<'c, C: DerefMut<Target = PgConnection> + Send + 'c>(
|
||||
|
||||
let stream: TryAsyncStream<'c, Bytes> = try_stream! {
|
||||
loop {
|
||||
let msg = conn.stream.recv().await?;
|
||||
match msg.format {
|
||||
MessageFormat::CopyData => r#yield!(msg.decode::<CopyData<Bytes>>()?.0),
|
||||
MessageFormat::CopyDone => {
|
||||
let _ = msg.decode::<CopyDone>()?;
|
||||
conn.stream.recv_expect(MessageFormat::CommandComplete).await?;
|
||||
match conn.stream.recv().await {
|
||||
Err(e) => {
|
||||
conn.stream.recv_expect(MessageFormat::ReadyForQuery).await?;
|
||||
return Ok(())
|
||||
return Err(e);
|
||||
},
|
||||
_ => return Err(err_protocol!("unexpected message format during copy out: {:?}", msg.format))
|
||||
Ok(msg) => match msg.format {
|
||||
MessageFormat::CopyData => r#yield!(msg.decode::<CopyData<Bytes>>()?.0),
|
||||
MessageFormat::CopyDone => {
|
||||
let _ = msg.decode::<CopyDone>()?;
|
||||
conn.stream.recv_expect(MessageFormat::CommandComplete).await?;
|
||||
conn.stream.recv_expect(MessageFormat::ReadyForQuery).await?;
|
||||
return Ok(())
|
||||
},
|
||||
_ => return Err(err_protocol!("unexpected message format during copy out: {:?}", msg.format))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user