From bad1dd975979e00ff8c5dbd0268ef74adf265f8a Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 14 Jan 2022 18:02:34 +0200 Subject: [PATCH] Don't panic if spawning a new WAL receiver thread fails. The panic would kill the page service thread. That's not too bad, but still let's try to handle it more gracefully. --- pageserver/src/page_service.rs | 2 +- pageserver/src/walreceiver.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pageserver/src/page_service.rs b/pageserver/src/page_service.rs index 7a5364b77b..c6de34b839 100644 --- a/pageserver/src/page_service.rs +++ b/pageserver/src/page_service.rs @@ -604,7 +604,7 @@ impl postgres_backend::Handler for PageServerHandler { tenant_mgr::get_timeline_for_tenant(tenantid, timelineid) .context("Failed to fetch local timeline for callmemaybe requests")?; - walreceiver::launch_wal_receiver(self.conf, tenantid, timelineid, &connstr); + walreceiver::launch_wal_receiver(self.conf, tenantid, timelineid, &connstr)?; pgb.write_message_noflush(&BeMessage::CommandComplete(b"SELECT 1"))?; } else if query_string.starts_with("branch_create ") { diff --git a/pageserver/src/walreceiver.rs b/pageserver/src/walreceiver.rs index 9dd1d14fe0..43c50746bd 100644 --- a/pageserver/src/walreceiver.rs +++ b/pageserver/src/walreceiver.rs @@ -107,7 +107,7 @@ pub fn launch_wal_receiver( tenantid: ZTenantId, timelineid: ZTimelineId, wal_producer_connstr: &str, -) { +) -> Result<()> { let mut receivers = WAL_RECEIVERS.lock(); match receivers.get_mut(&(tenantid, timelineid)) { @@ -122,8 +122,7 @@ pub fn launch_wal_receiver( .spawn(move || { IS_WAL_RECEIVER.with(|c| c.set(true)); thread_main(conf, tenantid, timelineid, rx); - }) - .unwrap(); + })?; let receiver = WalReceiverEntry { wal_producer_connstr: wal_producer_connstr.into(), @@ -134,10 +133,11 @@ pub fn launch_wal_receiver( receivers.insert((tenantid, timelineid), receiver); // Update tenant state and start tenant threads, if they are not running yet. - tenant_mgr::set_tenant_state(tenantid, TenantState::Active).unwrap(); + tenant_mgr::set_tenant_state(tenantid, TenantState::Active)?; tenant_threads::start_tenant_threads(conf, tenantid); } }; + Ok(()) } // Look up current WAL producer connection string in the hash table