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.
pull/2225/head^2
Jeff Mitchell 4 years ago committed by GitHub
parent 4cacd0a605
commit 396edfca80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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;
Loading…
Cancel
Save