Skip to content

Commit

Permalink
fix: ensures recover from fail with PgCopyIn (launchbadge#2179)
Browse files Browse the repository at this point in the history
* CHANGELOG: mention that users should upgrade CLI

* fix: ensures recover from fail with PgCopyIn

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
  • Loading branch information
2 people authored and Aandreba committed Mar 31, 2023
1 parent 0958a24 commit 7f18015
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions sqlx-postgres/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
conn.wait_until_ready().await?;
conn.stream.send(Query(statement)).await?;

let response: CopyResponse = conn
.stream
.recv_expect(MessageFormat::CopyInResponse)
.await?;
let response = match conn.stream.recv_expect(MessageFormat::CopyInResponse).await {
Ok(res) => res,
Err(e) => {
conn.stream.recv().await?;
return Err(e);
}
};

Ok(PgCopyIn {
conn: Some(conn),
Expand Down Expand Up @@ -299,10 +302,17 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
.expect("CopyWriter::finish: conn taken illegally");

conn.stream.send(CopyDone).await?;
let cc: CommandComplete = conn
let cc: CommandComplete = match conn
.stream
.recv_expect(MessageFormat::CommandComplete)
.await?;
.await
{
Ok(cc) => cc,
Err(e) => {
conn.stream.recv().await?;
return Err(e);
}
};

conn.stream
.recv_expect(MessageFormat::ReadyForQuery)
Expand Down

0 comments on commit 7f18015

Please sign in to comment.