You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When executing alter table operations concurrently, the DB.table_exists? call incorrectly returns false in situations where the underlying table exists but is locked by an external alter table operation. This issue arises when the #table_exists?'s underlying SELECT query gets canceled due to statement timeout. Consequently, a PG::QueryCanceled error is logged for the PostgreSQL adapter, while the method itself returns false.
This is particularly interesting for us because as part of our data processing pipeline, we execute many alter tables concurrently, which can sometimes result in the table being locked exclusively for a longer period than the statement timeout. Since there are strong ordering guarantees for processing incoming events we consider a missing target table as a data inconsistency issue and skip its execution. Therefore, before executing the next alter table operation, we have to check whether the target table already exists to decide whether to move it to the DLQ.
Simplest Possible Self-Contained Example Showing the Bug
Given there's a previously created table called customers
Lock that table with Access Exclusive lock: LOCK TABLE customers IN ACCESS EXCLUSIVE MODE;
Try issuing a DB.table_exists? call with the customers table parameter
Full Backtrace of Exception (if any)
No response
SQL Log (if any)
ERROR -- : PG::QueryCanceled: ERROR: canceling statement due to statement timeout: SELECT NULL AS "nil" FROM "customers" LIMIT 1
Ruby Version
3.2.0
Sequel Version
5.74.0
The text was updated successfully, but these errors were encountered:
Complete Description of Issue
When executing alter table operations concurrently, the
DB.table_exists?
call incorrectly returnsfalse
in situations where the underlying table exists but is locked by an external alter table operation. This issue arises when the#table_exists?
's underlyingSELECT
query gets canceled due to statement timeout. Consequently, aPG::QueryCanceled
error is logged for the PostgreSQL adapter, while the method itself returns false.This is particularly interesting for us because as part of our data processing pipeline, we execute many alter tables concurrently, which can sometimes result in the table being locked exclusively for a longer period than the statement timeout. Since there are strong ordering guarantees for processing incoming events we consider a missing target table as a data inconsistency issue and skip its execution. Therefore, before executing the next alter table operation, we have to check whether the target table already exists to decide whether to move it to the DLQ.
Simplest Possible Self-Contained Example Showing the Bug
customers
Access Exclusive
lock:LOCK TABLE customers IN ACCESS EXCLUSIVE MODE;
DB.table_exists?
call with thecustomers
table parameterFull Backtrace of Exception (if any)
No response
SQL Log (if any)
ERROR -- : PG::QueryCanceled: ERROR: canceling statement due to statement timeout: SELECT NULL AS "nil" FROM "customers" LIMIT 1
Ruby Version
3.2.0
Sequel Version
5.74.0
The text was updated successfully, but these errors were encountered: