@@ -329,38 +329,17 @@ where
329
329
and closed_reason is null
330
330
returning public_id;
331
331
`
332
- orphanedConnectionsCte = `
333
- -- Find connections that are not closed so we can reference those IDs
334
- with
335
- unclosed_connections as (
336
- select public_id
337
- from session_connection
338
- where
339
- -- It's not closed
340
- upper(connected_time_range) > now() or
341
- connected_time_range is null
342
- -- It's not in limbo between when it moved into this state and when
343
- -- it started being reported by the worker, which is roughly every
344
- -- 2-3 seconds
345
- and update_time < wt_sub_seconds_from_now(@worker_state_delay_seconds)
346
- ),
347
- connections_to_close as (
348
- select public_id
349
- from session_connection
350
- where
351
- -- Related to the worker that just reported to us
352
- worker_id = @worker_id
353
- -- Only unclosed ones
354
- and public_id in (select public_id from unclosed_connections)
355
- -- These are connection IDs that just got reported to us by the given
356
- -- worker, so they should not be considered closed.
357
- %s
358
- )
332
+ closeOrphanedConnections = `
359
333
update session_connection
360
- set
361
- closed_reason = 'system error'
362
- where
363
- public_id in (select public_id from connections_to_close)
334
+ set closed_reason = 'system error'
335
+ where worker_id = @worker_id
336
+ and update_time < wt_sub_seconds_from_now(@worker_state_delay_seconds)
337
+ and (
338
+ connected_time_range is null
339
+ or
340
+ upper(connected_time_range) > now()
341
+ )
342
+ %s
364
343
returning public_id;
365
344
`
366
345
deleteTerminated = `
0 commit comments