pgAdmin client crashes on dashboard state tab with high number of locks
Please note that security bugs or issues should be reported to [email protected].
Describe the bug This seems to be the same issue as #7809 and #7900 which is marked as fixed. I'm not sure whether there was a regression after that fix or my case is different so I decided to create a new issue.
I'm managing a database that has many partitioned tables (hundreds of partitions) and is used for data analytics with complex queries. From time to time, someone runs a suboptimal query that hits all partitions at once that results in thousands of locks being created. Anytime there are non-trivial number of locks in pg_locks table, the dashboard state tab freezes up and eventually causes the app to crash after a few minutes. The behavior is the same when pgAdmin is run in desktop mode or server mode. I have collected some stats in one of such crashes while running pgAdmin in server mode.
select count(1) from pg_stat_activity;
37
select count(1) from pg_stat_activity where state = 'active';
5
select count(1) from pg_locks;
54414
select count(1), pid from pg_locks group by pid;
2 3862383
13603 3866328
13603 3866379
13603 3866367
13603 3866350
I was monitoring the resource usage for the client Chrome tab and it raised up to 10GB memory with 100% CPU until it eventually crashed. The server process seemed to be doing fine with modest resource usage before, during, and after the freeze and the eventual crash.
To Reproduce
Steps to reproduce the behavior:
- Start running a few queries that acquire significant amount of locks (>1000)
- Click on Dashboard -> State
- Wait for a few seconds as the page loads with sessions.
- The sessions would be displayed followed by a freeze and an eventual crash.
Error message
There are no error messages in pgAdmin4 server logs.
Screenshots
Desktop (please complete the following information):
- OS: Ubuntu 24.04.3 LTS, Linux-6.14.0-33-generic-x86_64-with-glibc2.39
- pgAdmin version: v9.9
- Mode: both Desktop and Server
- Browser (if running in server mode): Chrome (v141)
- Package type: DEB from the official repo
Additional context
I understand that this case is a bit out of the ordinary with having tens of thousands of locks acquired by a handful of sessions. However, it's also the same reason why I want to be able to use the state tab to find out about these as a DBA and take necessary action.
In case that helps, I've added a screencast to demonstrate the issue. In an otherwise idle database, I opened the dashboard/state tab and started recording. In a separate terminal, I've issued a long running query that would generate ~1600 locks and hit the refresh button on the state tab. The tab is responsive for a few seconds after the refresh but completely freezes afterwards while the CPU usage hits 100% and memory usage starts climbing upwards continuously.
https://github.com/user-attachments/assets/d345ef2e-b1ed-4650-8daf-5987f6f66ba6
Hi @mvnural I created multiple locks in the range of 5k to 8k, and during scrolling, there is a slight blink or minor lag; however, the interface does not freeze or crash, as reported.
I also tested it in an Ubuntu VM, and although it hangs a bit more than my Mac, it still does not result in a complete freeze.
I tried reproducing it with and without the resizable changes, which we recently added to resize the section, but I couldn't reproduce it.
NOTE:- If the lock list is very large, we can also explore adding pagination or lazy loading to avoid UI overload.