Skip to content

Commit 5cefccc

Browse files
authored
Merge pull request #1121 from rust-lang/deadlock-begone
2 parents 0f564e6 + 13631b4 commit 5cefccc

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

compiler/base/orchestrator/src/coordinator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,8 +2848,10 @@ fn spawn_io_queue(stdin: ChildStdin, stdout: ChildStdout, token: CancellationTok
28482848
let stdin = SyncIoBridge::new(stdin);
28492849
let mut stdin = BufWriter::new(stdin);
28502850

2851+
let handle = tokio::runtime::Handle::current();
2852+
28512853
loop {
2852-
let coordinator_msg = futures::executor::block_on(async {
2854+
let coordinator_msg = handle.block_on(async {
28532855
select! {
28542856
() = token.cancelled() => None,
28552857
msg = rx.recv() => msg,

compiler/base/orchestrator/src/worker.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ impl ProcessState {
450450
let statistics_task = tokio::task::spawn_blocking({
451451
let child_id = child.id();
452452
let worker_msg_tx = worker_msg_tx.clone();
453-
move || stream_command_statistics(child_id, worker_msg_tx)
453+
let handle = tokio::runtime::Handle::current();
454+
move || stream_command_statistics(child_id, worker_msg_tx, handle)
454455
});
455456

456457
let task_set = stream_stdio(worker_msg_tx.clone(), stdin_rx, stdin, stdout, stderr);
@@ -943,6 +944,7 @@ mod stats {
943944
fn stream_command_statistics(
944945
child_id: Option<u32>,
945946
worker_msg_tx: MultiplexingSender,
947+
handle: tokio::runtime::Handle,
946948
) -> Result<(), CommandStatisticsError> {
947949
use command_statistics_error::*;
948950
use stats::*;
@@ -959,7 +961,7 @@ fn stream_command_statistics(
959961
let process = Process::new(process_id).context(InvalidProcessSnafu { process_id })?;
960962

961963
while let Some(stats) = process.stats() {
962-
let sent = futures::executor::block_on(worker_msg_tx.send_ok(stats));
964+
let sent = handle.block_on(worker_msg_tx.send_ok(stats));
963965
if sent.is_err() {
964966
// No one listening anymore
965967
break;

ui/src/request_database.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl Handle {
215215
let g = self
216216
.attempt_start_request(category, payload)
217217
.await
218-
.map(|id| EndGuardInner(id, How::Abandoned, self));
218+
.map(|id| EndGuardInner(id, How::Abandoned, Some(self)));
219219
EndGuard(g)
220220
}
221221
}
@@ -238,12 +238,16 @@ impl EndGuard {
238238
}
239239
}
240240

241-
struct EndGuardInner(Id, How, Handle);
241+
struct EndGuardInner(Id, How, Option<Handle>);
242242

243243
impl Drop for EndGuardInner {
244244
fn drop(&mut self) {
245-
let Self(id, how, ref handle) = *self;
246-
futures::executor::block_on(handle.attempt_end_request(id, how))
245+
let Self(id, how, ref mut handle) = *self;
246+
if let Ok(h) = tokio::runtime::Handle::try_current() {
247+
if let Some(handle) = handle.take() {
248+
h.spawn(async move { handle.attempt_end_request(id, how).await });
249+
}
250+
}
247251
}
248252
}
249253

ui/src/server_axum.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::{
3838
sync::{Arc, LazyLock},
3939
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
4040
};
41-
use tokio::sync::Mutex;
41+
use tokio::{select, sync::Mutex};
4242
use tower_http::{
4343
cors::{self, CorsLayer},
4444
request_id::{MakeRequestUuid, PropagateRequestIdLayer, SetRequestIdLayer},
@@ -71,7 +71,7 @@ pub(crate) async fn serve(config: Config) {
7171
let factory = Factory(Arc::new(config.coordinator_factory()));
7272

7373
let request_db = config.request_database();
74-
let (_db_task, db_handle) = request_db.spawn();
74+
let (db_task, db_handle) = request_db.spawn();
7575

7676
let root_files = static_file_service(config.root_path(), MAX_AGE_ONE_DAY);
7777
let asset_files = static_file_service(config.asset_path(), MAX_AGE_ONE_YEAR);
@@ -170,9 +170,12 @@ pub(crate) async fn serve(config: Config) {
170170
.await
171171
.unwrap();
172172

173-
axum::serve(listener, app.into_make_service())
174-
.await
175-
.unwrap();
173+
let server = axum::serve(listener, app.into_make_service());
174+
175+
select! {
176+
v = server => v.unwrap(),
177+
v = db_task => v.unwrap(),
178+
}
176179
}
177180

178181
fn get_or_post<T: 'static>(handler: impl Handler<T, ()> + Copy) -> MethodRouter {

0 commit comments

Comments
 (0)