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

PG::ConnectionBad: PQsocket() can't get socket descriptor: ROLLBACK #64

Open
ajparise opened this issue Mar 24, 2023 · 2 comments
Open

Comments

@ajparise
Copy link

Our app opens a cursor which can run for hours at a time.
On the longer runs (7+ hours) the cursor occasionally errors out with:

ActiveRecord::StatementInvalid
PG::ConnectionBad: PQsocket() can't get socket descriptor: ROLLBACK

I am trying to rule this gem out as the culprit. I'm not sure if this is masking a different error.
Should we be passing with_hold: true in the options?

Here is a snippet of the cursor loop:

# BATCH_SIZE = 10_000
 records.each_instance(block_size: BATCH_SIZE) { |record| @handler.call(record) }

Couple things that may or may not be pertinent:

  • We tried upgrading to 0.6.7 and see the same behavior
  • The records returned by the cursor have associations on them.
  • App makes other read only ActiveRecord calls within the block passed to #each_instance
    • these read only calls do not access the same table as the cursor
@guemidiborhane
Copy link

+1 we're having the same issue but only in production.

@guemidiborhane
Copy link

guemidiborhane commented Aug 19, 2023

After some investigations, seems like the issue in our case is related to the query being run against replica postgresql server, fixed by setting this 2 config lines in postgresql.conf:

max_standby_archive_delay = 600s 
max_standby_streaming_delay = 600s

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

2 participants