quicktill icon indicating copy to clipboard operation
quicktill copied to clipboard

Lock sessions table when opening a new session

Open sde1000 opened this issue 1 year ago • 2 comments

If two people try to start a session at exactly the same time, two open sessions can be created.

Take an exclusive lock on the sessions table during session creation to prevent this.

sde1000 avatar Jan 09 '25 13:01 sde1000

(Amazingly, this came up for the first time in 20 years, this week!)

sde1000 avatar Jan 09 '25 13:01 sde1000

The easiest way to do this Properly™ would be to add a unique constraint on endtime with the SQL NULLS NOT DISTINCT clause — that way, at most one row could have a null endtime.

Unfortunately, this was only implemented in Postgresql 15 — most current installations are using Postgresql 14 (or earlier).

Since this has only come up once in 20 years, we could wait a while before fixing it...

sde1000 avatar Jan 13 '25 14:01 sde1000