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

Surprising infinite retrying of SQL statement on a replica causes replication lag #3673

Open
steve-chavez opened this issue Aug 1, 2024 · 1 comment
Labels

Comments

@steve-chavez
Copy link
Member

steve-chavez commented Aug 1, 2024

Problem

On a read replica, this happens:

GET /rpc/xx..

Jul 22 23:21:04 [redacted] postgrest[115960]: 22/Jul/2024:23:21:04 +0000: 
{"code":"40001",
"details":"User query might have needed to see row versions that must be removed.",
"hint":null,
"message":"canceling statement due to conflict with recovery"}

On the postgres logs, this error is repeated infinitely:

..,ERROR,40001,"canceling statement due to conflict with recovery","User query might have needed to see row versions that must be removed.",,
PL/pgSQL function xx() line 3 at RETURN QUERY","WITH pgrst_source AS (SELECT ""pgrst_call"".
...

For some reason this causes noticeable replication lag, I'm assuming this error somehow affects the replication process. It can only be solved if postgrest is stopped.

The problem root cause can be found on hasql-transaction:

Solution

Don't retry on 40001. We would need to patch hasql-transaction to make the retrying behavior configurable and then disable it.

Notes

This is hard to reproduce. But I think we shouldn't do any retrying by default.

@steve-chavez steve-chavez changed the title Surprising retrying of SQL statement on a replica causes replication lag Surprising infinite retrying of SQL statement on a replica causes replication lag Aug 2, 2024
@wolfgangwalther
Copy link
Member

The problem root cause can be found on hasql-transaction:

Doesn't seem like a PostgREST bug, but a hasql bug, then?

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

No branches or pull requests

2 participants