Skip to content

Commit 13e2e29

Browse files
committed
Handle requests received after shutdown message
1 parent cfc6941 commit 13e2e29

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

crates/ruff_server/src/server/connection.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,37 @@ impl Connection {
9191
self.sender
9292
.send(lsp::Response::new_ok(id.clone(), ()).into())?;
9393
tracing::info!("Shutdown request received. Waiting for an exit notification...");
94-
match self.receiver.recv_timeout(std::time::Duration::from_secs(30))? {
95-
lsp::Message::Notification(lsp::Notification { method, .. }) if method == lsp_types::notification::Exit::METHOD => {
96-
tracing::info!("Exit notification received. Server shutting down...");
97-
Ok(true)
98-
},
99-
message => anyhow::bail!("Server received unexpected message {message:?} while waiting for exit notification")
94+
95+
loop {
96+
match &self
97+
.receiver
98+
.recv_timeout(std::time::Duration::from_secs(30))?
99+
{
100+
lsp::Message::Notification(lsp::Notification { method, .. })
101+
if method == lsp_types::notification::Exit::METHOD =>
102+
{
103+
tracing::info!("Exit notification received. Server shutting down...");
104+
return Ok(true);
105+
}
106+
lsp::Message::Request(lsp::Request { id, .. }) => {
107+
self.sender.send(lsp::Message::Response(lsp::Response::new_err(
108+
id.clone(),
109+
lsp::ErrorCode::InvalidRequest as i32,
110+
"Server received unexpected request while waiting for exit notification".to_string(),
111+
)))?;
112+
}
113+
message => {
114+
anyhow::bail!(
115+
"Server received unexpected message {message:?} while waiting for exit notification"
116+
)
117+
}
118+
}
100119
}
101120
}
102121
lsp::Message::Notification(lsp::Notification { method, .. })
103122
if method == lsp_types::notification::Exit::METHOD =>
104123
{
105-
tracing::error!("Server received an exit notification before a shutdown request was sent. Exiting...");
106-
Ok(true)
124+
anyhow::bail!("Server received an exit notification before a shutdown request was sent. Exiting...");
107125
}
108126
_ => Ok(false),
109127
}

0 commit comments

Comments
 (0)