Skip to content

Commit 1b008f4

Browse files
chore: Remove unnecessary spawn (risingwavelabs#8722)
1 parent a1d084d commit 1b008f4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/batch/src/task/task_execution.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
use std::fmt::{Debug, Formatter};
1616
use std::future::Future;
17+
use std::panic::AssertUnwindSafe;
1718
use std::sync::Arc;
1819
use std::time::Duration;
1920

20-
use futures::StreamExt;
21+
use futures::{FutureExt, StreamExt};
2122
use minitrace::prelude::*;
2223
use parking_lot::Mutex;
2324
use risingwave_common::array::DataChunk;
@@ -370,7 +371,6 @@ impl<C: BatchTaskContext> BatchTaskExecution<C> {
370371

371372
// Clone `self` to make compiler happy because of the move block.
372373
let t_1 = self.clone();
373-
let t_2 = self.clone();
374374
// Spawn task for real execution.
375375
let fut = async move {
376376
trace!("Executing plan [{:?}]", task_id);
@@ -394,9 +394,9 @@ impl<C: BatchTaskContext> BatchTaskExecution<C> {
394394

395395
if let Some(task_metrics) = task_metrics {
396396
let monitor = TaskMonitor::new();
397-
let join_handle = t_2.runtime.spawn(monitor.instrument(task(task_id.clone())));
398-
if let Err(join_error) = join_handle.await && join_error.is_panic() {
399-
error!("Batch task {:?} panic!", task_id);
397+
let instrumented_task = AssertUnwindSafe(monitor.instrument(task(task_id.clone())));
398+
if let Err(error) = instrumented_task.catch_unwind().await {
399+
error!("Batch task {:?} panic: {:?}", task_id, error);
400400
}
401401
let cumulative = monitor.cumulative();
402402
let labels = &task_metrics.task_labels();
@@ -425,11 +425,9 @@ impl<C: BatchTaskContext> BatchTaskExecution<C> {
425425
.task_slow_poll_duration
426426
.with_label_values(labels)
427427
.set(cumulative.total_slow_poll_duration.as_secs_f64());
428-
} else {
429-
let join_handle = t_2.runtime.spawn(task(task_id.clone()));
430-
if let Err(join_error) = join_handle.await && join_error.is_panic() {
431-
error!("Batch task {:?} panic!", task_id);
432-
}
428+
} else if let Err(error) = AssertUnwindSafe(task(task_id.clone())).catch_unwind().await
429+
{
430+
error!("Batch task {:?} panic: {:?}", task_id, error);
433431
}
434432
};
435433

0 commit comments

Comments
 (0)