From 1e57ddaabc2b69752bf7b9329382da4b1e24ce63 Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Thu, 30 Nov 2023 14:26:11 +0200 Subject: [PATCH] fix: flush loop should also keep the gate open (#5987) I was expecting this to already be in place, because this should not conflict how we shutdown (0. cancel, 1. shutdown_tasks, 2. close gate). --- pageserver/src/tenant/timeline.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pageserver/src/tenant/timeline.rs b/pageserver/src/tenant/timeline.rs index 24f59673c1..9a7c9a6df3 100644 --- a/pageserver/src/tenant/timeline.rs +++ b/pageserver/src/tenant/timeline.rs @@ -1488,6 +1488,10 @@ impl Timeline { } pub(super) fn maybe_spawn_flush_loop(self: &Arc) { + let Ok(guard) = self.gate.enter() else { + info!("cannot start flush loop when the timeline gate has already been closed"); + return; + }; let mut flush_loop_state = self.flush_loop_state.lock().unwrap(); match *flush_loop_state { FlushLoopState::NotStarted => (), @@ -1525,6 +1529,7 @@ impl Timeline { "layer flush task", false, async move { + let _guard = guard; let background_ctx = RequestContext::todo_child(TaskKind::LayerFlushTask, DownloadBehavior::Error); self_clone.flush_loop(layer_flush_start_rx, &background_ctx).await; let mut flush_loop_state = self_clone.flush_loop_state.lock().unwrap();