Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL code used by some containers can cause PG deadlocks, and the containers crash in response #357

Open
simon-20 opened this issue Nov 20, 2024 · 0 comments

Comments

@simon-20
Copy link
Collaborator

Brief Description
This issue occurs regularly but not frequently, and has been doing so as far as our logs go back. The issue is that some of the SQL UPDATE commands which reset the *_start flags for each pipeline stage can enter deadlock. Here's an example from the Postgres logs:

2024-11-20 00:20:47 UTC-673d2b5e.880d0-ERROR:  deadlock detected
2024-11-20 00:20:47 UTC-673d2b5e.880d0-DETAIL:  Process 557264 waits for ShareLock on transaction 868302883; blocked by process 557268.
	Process 557268 waits for ShareLock on transaction 868302881; blocked by process 557264.
	Process 557264: 
	        UPDATE document
	        SET clean_start = null
	        WHERE clean_end is null
	    
	Process 557268: 
	        UPDATE document
	        SET flatten_start=null
	        WHERE flatten_end is null

This can happen (even though the data being updated is not the same) because Postgres locks the entire row when updating, the two updates may contain the same rows, and the order in which UPDATE processes the rows is not deterministic.

Severity
High

Issue Location
one of the database statements above

Expected Results/Behaviour
Minimum: the containers should not crash when deadlocks occur.
Ideal: use SELECT FOR UPDATE to ensure the UPDATEs process records in the same order; this should then cause one to wait for another, and avoid deadlock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant