Skip to content

Commit

Permalink
fix(turborepo): Handle unimplemented and failed_precondition in daemo…
Browse files Browse the repository at this point in the history
…n clients (#5151)

Co-authored-by: Greg Soltis <Greg Soltis>
  • Loading branch information
Greg Soltis authored and Greg Soltis committed May 31, 2023
1 parent 901c4a3 commit f2ae81a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cli/internal/daemon/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ func (c *Connector) sendHello(ctx context.Context, client turbodprotocol.TurbodC
switch status.Code() {
case codes.OK:
return nil
case codes.Unimplemented:
fallthrough // some versions of the rust daemon return Unimplemented rather than FailedPrecondition
case codes.FailedPrecondition:
return ErrVersionMismatch
case codes.Unavailable:
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/daemon/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub enum DaemonError {
impl From<Status> for DaemonError {
fn from(status: Status) -> DaemonError {
match status.code() {
Code::FailedPrecondition => DaemonError::VersionMismatch,
Code::FailedPrecondition | Code::Unimplemented => DaemonError::VersionMismatch,
Code::Unavailable => DaemonError::Unavailable,
c => DaemonError::GrpcFailure(c),
}
Expand Down
9 changes: 7 additions & 2 deletions crates/turborepo-lib/src/daemon/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ impl<T: Watcher + Send + 'static> proto::turbod_server::Turbod for DaemonServer<
&self,
request: tonic::Request<proto::HelloRequest>,
) -> Result<tonic::Response<proto::HelloResponse>, tonic::Status> {
if request.into_inner().version != get_version() {
return Err(tonic::Status::unimplemented("version mismatch"));
let client_version = request.into_inner().version;
let server_version = get_version();
if client_version != server_version {
return Err(tonic::Status::failed_precondition(format!(
"version mismatch. Client {} Server {}",
client_version, server_version
)));
} else {
Ok(tonic::Response::new(proto::HelloResponse {}))
}
Expand Down

0 comments on commit f2ae81a

Please sign in to comment.