Make reconnects smoother for dev servers (#12223)

Release Notes:

- N/A

Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Conrad Irwin 2024-05-23 21:11:14 -06:00 committed by GitHub
parent 656edc4b2e
commit 3ec94697b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 9 deletions

View File

@ -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);
}
@ -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;
}
@ -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;
}

View File

@ -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 {

View File

@ -510,6 +510,7 @@ message CreateDevServerResponse {
}
message ShutdownDevServer {
optional string reason = 1;
}
message RenameDevServer {