Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensures recover from fail with PgCopyIn #2179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [[#2057]]: Make begin,commit,rollback cancel-safe in sqlite [[@madadam]]
* [[#2058]]: fix typo in documentation [[@lovasoa]]
* [[#2067]]: fix(docs): close code block in query_builder.rs [[@abonander]]
* [[#2069]]: Fix `prepare` race condition in workspaces [[@cycraig]]
* [[#2069]]: Fix `prepare` race condition in workspaces [[@cycraig]]\
* NOTE: this changes the directory structure under `target/` that `cargo sqlx prepare` depends on.
If you use offline mode in your workflow, please rerun `cargo install sqlx-cli` to upgrade.
* [[#2072]]: SqliteConnectOptions typo [[@fasterthanlime]]
* [[#2074]]: fix: mssql uses unsigned for tinyint instead of signed [[@he4d]]
* [[#2081]]: close unnamed portal after each executed extended query [[@DXist]]
Expand Down
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