Skip to content

Commit

Permalink
Make reconnects smoother for dev servers (#12223)
Browse files Browse the repository at this point in the history
Release Notes:

- N/A

Co-authored-by: Nathan <[email protected]>
  • Loading branch information
ConradIrwin and nathansobo authored May 24, 2024
1 parent 656edc4 commit 3ec9469
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
31 changes: 23 additions & 8 deletions crates/collab/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,17 @@ impl Server {
Principal::DevServer(dev_server) => {
{
let mut pool = self.connection_pool.lock();
if pool.dev_server_connection_id(dev_server.id).is_some() {
return Err(anyhow!(ErrorCode::DevServerAlreadyOnline))?;
if let Some(stale_connection_id) = pool.dev_server_connection_id(dev_server.id)
{
self.peer.send(
stale_connection_id,
proto::ShutdownDevServer {
reason: Some(
"another dev server connected with the same token".to_string(),
),
},
)?;
pool.remove_connection(stale_connection_id)?;
};
pool.add_dev_server(connection_id, dev_server.id, zed_version);
}
Expand Down Expand Up @@ -2398,9 +2407,12 @@ async fn regenerate_dev_server_token(
.dev_server_connection_id(dev_server_id);
if let Some(connection_id) = connection_id {
shutdown_dev_server_internal(dev_server_id, connection_id, &session).await?;
session
.peer
.send(connection_id, proto::ShutdownDevServer {})?;
session.peer.send(
connection_id,
proto::ShutdownDevServer {
reason: Some("dev server token was regenerated".to_string()),
},
)?;
let _ = remove_dev_server_connection(dev_server_id, &session).await;
}

Expand Down Expand Up @@ -2470,9 +2482,12 @@ async fn delete_dev_server(
.dev_server_connection_id(dev_server_id);
if let Some(connection_id) = connection_id {
shutdown_dev_server_internal(dev_server_id, connection_id, &session).await?;
session
.peer
.send(connection_id, proto::ShutdownDevServer {})?;
session.peer.send(
connection_id,
proto::ShutdownDevServer {
reason: Some("dev server was deleted".to_string()),
},
)?;
let _ = remove_dev_server_connection(dev_server_id, &session).await;
}

Expand Down
5 changes: 4 additions & 1 deletion crates/headless/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ impl DevServer {
let request = if self.remote_shutdown {
None
} else {
Some(self.client.request(proto::ShutdownDevServer {}))
Some(
self.client
.request(proto::ShutdownDevServer { reason: None }),
)
};
async move {
if let Some(request) = request {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/proto/zed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ message CreateDevServerResponse {
}

message ShutdownDevServer {
optional string reason = 1;
}

message RenameDevServer {
Expand Down

0 comments on commit 3ec9469

Please sign in to comment.