Replies: 5 comments 13 replies
-
Maybe a slight tangent, but if I implemented schema caching, would that prevent this specific error because the schema is guaranteed to be available? (Obviously we’d still see some error when the DB connection glitches, but this particular issue was harder to track down than a ‘regular’ DB connection problem 😅 ) |
Beta Was this translation helpful? Give feedback.
-
By default, a failure to load the model schema should raise an exception, it shouldn't be silently swallowed. If it is being silently swallowed, my guess is you have set require_valid_table to false, which is a terrible idea. Alternatively, you are using a very old version of Sequel and should upgrade.
This would be expected if Sequel cannot determine the table schema. Obviously, this is a bad thing, which is why Sequel sets require_valid_table to true by default.
Yes, the schema_caching extension would probably help prevent this particular type of error. One potential issue I see is that the UnableToSend exception is not treated as a disconnect error. What happens on future use of the same connection? Do you get a different error that is treated as a disconnect error? I would assume you must, otherwise you would have a disconnected connection in the pool that would continuously cause problems every time it is used. You could try the following patch and see if helps, though it is unlikely to be related to this specific issue: index fe9292c30..0eeec582a 100644
--- a/lib/sequel/adapters/postgres.rb
+++ b/lib/sequel/adapters/postgres.rb
@@ -52,6 +52,9 @@ module Sequel
if defined?(::PG::ConnectionBad)
DISCONNECT_ERROR_CLASSES << ::PG::ConnectionBad
end
+ if defined?(::PG::UnableToSend)
+ DISCONNECT_ERROR_CLASSES << ::PG::UnableToSend
+ end
DISCONNECT_ERROR_CLASSES.freeze
disconnect_errors = [ |
Beta Was this translation helpful? Give feedback.
-
Hi @jeremyevans, thanks so much for your help, the changes we discussed above seem to have solved this issue. I was able to get a full backtrace for the original exception by redefining
The lines in our application code here don’t look significant. They are: 48: Entrypoint for the Resque job Backtrace line 34 is the definition of the class which blows up later on: The Zeitwerk lines in between our application code lines are in Zeitwerk’s override of |
Beta Was this translation helpful? Give feedback.
-
To see if this problem is somewhere in Sequel, can you override |
Beta Was this translation helpful? Give feedback.
-
Overriding
I see |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, we’re having occasional database connection issues that are nothing to do with Sequel, but they are causing a knock-on effect in Sequel which I don’t know how to recover from.
What happens is:
PG::UnableToSend: SSL SYSCALL error: EOF detected: SELECT \"pg_attribute\".\"attname\" AS \"name\", CAST(\" ... etc
PG::UndefinedColumn: ERROR: column \"customer_id\" does not exist
What I’d like to know is how I ought to be recovering from this? Nothing is raised when 1 fails, only when 2 does, so I don’t see an opportunity to retry at that point. If I rescue
PG::UndefinedColumn
then willDatabase#schema(:billing_infos, reload: true)
reload the schema that Sequel::Model also refers to?If I always want to retry something like this at least once, is there a way to tell that to Sequel? I’m happy to structure higher-level code so it always tries to rescue and repair the situation, but maybe I’m missing something here.
Notes
The error in 2 is strictly correct, column
customer_id
does not exist. But that’s not what’s being asked for, as seen in the Ruby code when this error occurs:Here
invoice
is a Sequel::Model instance,payment_method
is an object we got from Stripe’s API, and the relationsinvoice.user
anduser.billing_infos
are configured and work. Cruciallypayment_details
is a JSON column, socustomer_id
is supposed to be a key in a JSON object, not a column name.This code works as intended most of the time!
Beta Was this translation helpful? Give feedback.
All reactions