Skip to content

Commit 49b63b7

Browse files
committed
[HACK] Fix deadlock by avoiding backpressure for fresh jobs
1 parent 3836dfb commit 49b63b7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ pub struct JobState<'a> {
166166
/// Channel back to the main thread to coordinate messages and such.
167167
messages: Arc<Queue<Message>>,
168168

169+
/// Normally messages are handled in a bounded way. When the job is fresh
170+
/// however we need to immediately return to prevent a deadlock as the messages
171+
/// are processed on the same thread as they are sent from.
172+
messages_bounded: bool,
173+
169174
/// The job id that this state is associated with, used when sending
170175
/// messages back to the main thread.
171176
id: JobId,
@@ -232,11 +237,19 @@ impl<'a> JobState<'a> {
232237
}
233238

234239
pub fn stdout(&self, stdout: String) {
235-
self.messages.push_bounded(Message::Stdout(stdout));
240+
if self.messages_bounded {
241+
self.messages.push_bounded(Message::Stdout(stdout));
242+
} else {
243+
self.messages.push(Message::Stdout(stdout));
244+
}
236245
}
237246

238247
pub fn stderr(&self, stderr: String) {
239-
self.messages.push_bounded(Message::Stderr(stderr));
248+
if self.messages_bounded {
249+
self.messages.push_bounded(Message::Stderr(stderr));
250+
} else {
251+
self.messages.push(Message::Stderr(stderr));
252+
}
240253
}
241254

242255
/// A method used to signal to the coordinator thread that the rmeta file
@@ -830,6 +843,7 @@ impl<'cfg> DrainState<'cfg> {
830843
let state = JobState {
831844
id,
832845
messages: messages.clone(),
846+
messages_bounded: job.freshness() == Freshness::Dirty,
833847
rmeta_required: Cell::new(rmeta_required),
834848
_marker: marker::PhantomData,
835849
};

0 commit comments

Comments
 (0)