Skip to content

Commit f880078

Browse files
committed
Idle coordinator after the last execution
Previously, we recreated the sleep every time we entered the `select!`. This worked great... until we added the active executions garbage collection. That caused the select to restart every 30 seconds and we never got around to the idle condition which would take 60 seconds!
1 parent 75d984f commit f880078

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ui/src/server_axum/websocket.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
};
77

88
use axum::extract::ws::{Message, WebSocket};
9-
use futures::{Future, FutureExt, StreamExt, TryFutureExt};
9+
use futures::{future::Fuse, Future, FutureExt, StreamExt, TryFutureExt};
1010
use orchestrator::{
1111
coordinator::{self, Coordinator, DockerBackend},
1212
DropErrorDetailsExt,
@@ -353,6 +353,7 @@ async fn handle_core(mut socket: WebSocket, feature_flags: FeatureFlags) {
353353

354354
let mut manager = CoordinatorManager::new().await;
355355
let mut session_timeout = pin!(time::sleep(CoordinatorManager::SESSION_TIMEOUT));
356+
let mut idle_timeout = pin!(Fuse::terminated());
356357

357358
let mut active_executions = BTreeMap::new();
358359
let mut active_execution_gc_interval = time::interval(Duration::from_secs(30));
@@ -393,6 +394,12 @@ async fn handle_core(mut socket: WebSocket, feature_flags: FeatureFlags) {
393394

394395
// We don't care if there are no running tasks
395396
Some(task) = manager.join_next() => {
397+
// The last task has completed which means we are a
398+
// candidate for idling in a little while.
399+
if manager.is_empty() {
400+
idle_timeout.set(time::sleep(CoordinatorManager::IDLE_TIMEOUT).fuse());
401+
}
402+
396403
let (error, meta) = match task {
397404
Ok(Ok(())) => continue,
398405
Ok(Err(error)) => error,
@@ -424,7 +431,7 @@ async fn handle_core(mut socket: WebSocket, feature_flags: FeatureFlags) {
424431
.collect();
425432
},
426433

427-
_ = time::sleep(CoordinatorManager::IDLE_TIMEOUT), if manager.is_empty() => {
434+
_ = &mut idle_timeout, if manager.is_empty() => {
428435
let idled = manager.idle().await.context(StreamingCoordinatorIdleSnafu);
429436

430437
let Err(error) = idled else { continue };

0 commit comments

Comments
 (0)