From 396edfca803b62b7fc222d838c14e6a57003bebf Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 23 Jun 2022 12:25:55 -0400 Subject: [PATCH] Add an extra cleanup task for sessions stuck in canceling state (#2229) * Add an extra cleanup task for sessions stuck in canceling state See the comment on the migrations file for details. --- CHANGELOG.md | 17 +++-- .../oss/postgres/35/02_cleanup.up.sql | 74 +++++++++++++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 internal/db/schema/migrations/oss/postgres/35/02_cleanup.up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b696d878..7ff154c89b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,16 +6,21 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ### Bug Fixes -* scheduler: Removes a Postgres check constraint on the length of the controller id. - The constraint causes an error when running jobs with controllers configured - with a name of less than 10 character: - `controller_id_must_be_at_least_10_characters constraint failed`. - Since a controller's name is used as its private id, Boundary does not enforce - the normal length requirements on the `server_controller` table +* scheduler: Fix regression causing controller names of less than 10 characters + to fail to register jobs ([PR](https://github.com/hashicorp/boundary/pull/2226)). +* sessions: Fix an additional case from the changes in the 0.8.x series that + could result in sessions never moving from `canceling` state to terminated. + ([PR](https://github.com/hashicorp/boundary/pull/2229)) ## 0.9.0 (2022/06/20) +### Known Issues + +* If a controller's defined name in a configuration file is less than 10 + characters, errors may be seen on startup related to registration of jobs. + This is a regression in this version and will be fixed in the next release. + ### New and Improved * PKI Workers: This release introduces a new worker type `pki` which diff --git a/internal/db/schema/migrations/oss/postgres/35/02_cleanup.up.sql b/internal/db/schema/migrations/oss/postgres/35/02_cleanup.up.sql new file mode 100644 index 0000000000..b408d33d7d --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/35/02_cleanup.up.sql @@ -0,0 +1,74 @@ +begin; + +-- This adds additional cleanup to what went into 0.8.x. There could be a case +-- where sessions can persist in canceled state even if there are no connections +-- for that session (possibly due to cleanup) and will never be transitioned +-- because connection state cannot be determined. +-- +-- If they have previously been marked terminated in the warehouse we delete +-- them; if not we mark them terminated so it's recorded in the warehouse and +-- the cleanup job should eventually clear these out. +with + canceling_sessions(session_id) as ( + select session_id + from session_state + where state = 'canceling' + and end_time is null + ), + no_connection_canceling_sessions as ( + select session_id + from canceling_sessions + where session_id not in + ( + select session_id + from session_connection + ) + ), + has_termination_reason (session_id) as ( + select public_id + from session + where public_id in + ( + select session_id + from no_connection_canceling_sessions + ) + and termination_reason is not null + ), + terminated_in_warehouse (session_id) as ( + select session_id + from has_termination_reason + where session_id in + ( + select session_id + from wh_session_accumulating_fact + where session_terminated_date_key <> -1 + ) + ), + not_terminated_in_warehouse (session_id) as ( + select session_id + from has_termination_reason + where session_id not in + ( + select session_id + from terminated_in_warehouse + ) + ), + delete_terminated_in_warehouse_from_session as ( + delete from session + where public_id in + ( + select session_id + from terminated_in_warehouse + ) + ) + update session + set + version = version + 1, + termination_reason = 'canceled' + where public_id in + ( + select session_id + from not_terminated_in_warehouse + ); + +commit; \ No newline at end of file