N
Neon5mo ago
other-emerald

Intermittently throwing error when trying to acquire lock

Some times despite no existing lock acquired against a particular column, it throws error. Its very random and very frustrating. We are using select for update query with noupdate option. I have also tried disabling the Scale to zero setting. Please help this is very annoying.
3 Replies
other-emerald
other-emeraldOP5mo ago
This is the error we get
org.springframework.dao.DataAccessResourceFailureException: executeMany; SQL [ SELECT
available_tokens
FROM users
WHERE
id = $1
FOR UPDATE NOWAIT;
]; could not obtain lock on row in relation "users"
org.springframework.dao.DataAccessResourceFailureException: executeMany; SQL [ SELECT
available_tokens
FROM users
WHERE
id = $1
FOR UPDATE NOWAIT;
]; could not obtain lock on row in relation "users"
wise-white
wise-white5mo ago
The reason for this is because this lock is already acquired by something else. NOWAIT option tells to immediately error out in this case instead of trying to wait for the lock to get released. Even without NOWAIT you can get to a place where you timeout waiting and will get an error anyways. So you have to retry accordingly
other-emerald
other-emeraldOP4mo ago
Thats not correct. If its already locked, it throws explicit error saying lock is already acquired.

Did you find this page helpful?