diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h @@ -51,15 +51,18 @@ template void ClientBidiReactorBase::terminate( const grpc::Status &status) { - this->terminateCallback(); - if (this->done) { - return; - } + this->status = status; if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } + if (this->done) { + std::cout << "Terminate function was called multiple times, which should " + "never happen. Please investigate!" + << std::endl; + return; + } + this->terminateCallback(); this->StartWritesDone(); - this->status = status; this->done = true; } @@ -79,7 +82,10 @@ template void ClientBidiReactorBase::OnReadDone(bool ok) { if (!ok) { - this->terminate(grpc::Status(grpc::StatusCode::UNKNOWN, "read error")); + // Ending a connection on the other side results in the `ok` flag being set + // to false. It makes it impossible to detect a failure based just on the + // flag. We should manually check if the data we received is valid + this->terminate(grpc::Status::OK); return; } this->nextWrite(); diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h @@ -31,14 +31,17 @@ template void ClientReadReactorBase::terminate( const grpc::Status &status) { - this->terminateCallback(); - if (this->done) { - return; - } + this->status = status; if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } - this->status = status; + if (this->done) { + std::cout << "Terminate function was called multiple times, which should " + "never happen. Please investigate!" + << std::endl; + return; + } + this->terminateCallback(); this->done = true; } @@ -54,7 +57,10 @@ template void ClientReadReactorBase::OnReadDone(bool ok) { if (!ok) { - this->terminate(grpc::Status(grpc::StatusCode::UNKNOWN, "read error")); + // Ending a connection on the other side results in the `ok` flag being set + // to false. It makes it impossible to detect a failure based just on the + // flag. We should manually check if the data we received is valid + this->terminate(grpc::Status::OK); return; } std::unique_ptr status = this->readResponse(this->response); diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h @@ -53,14 +53,17 @@ template void ClientWriteReactorBase::terminate( const grpc::Status &status) { - this->terminateCallback(); - if (this->done) { - return; - } + this->status = status; if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } - this->status = status; + if (this->done) { + std::cout << "Terminate function was called multiple times, which should " + "never happen. Please investigate!" + << std::endl; + return; + } + this->terminateCallback(); this->done = true; this->StartWritesDone(); }