Replies: 3 comments 5 replies
-
This is thread safe. |
Beta Was this translation helpful? Give feedback.
-
Hi Jeremy, When you mentioned that only 'the hash access needs a mutex check', did you mean '_trans(conn) which is Sequel.synchronize{@Transactions[conn]}' or '_trans(conn)[:savepoints]' ? Just want to run through you the following scenarios with the current [:savepoints] contains 2 elements: Just try to dig deeper about the possibility here, because we experienced an error 'undefined method [] for nil class' (from the line: if opts[:savepoint] != false && (stack = _trans(conn)[:savepoints]) && stack.last[:auto_savepoint] - line 221 transactions.rb)) while running many concurrent processing that has many DB.transaction boundary, and cannot recover from the error unless re-initialize the DB connection. Thank you for your help. |
Beta Was this translation helpful? Give feedback.
-
Hi Jeremy, Thank you for your response and advice, really appreciate it. Unfortunately, we do not have a self contained example that can keep reproducing the issue. The error occurred twice (first time on 19 Jan and second time on 17 Feb) on an environment that runs many concurrent processes running 24/7 and access the same database. The first time the error is 'cannot set :retry_on options if you are already inside a transaction' and the second time is 'undefined method `[]' for nil:NilClass' (both from within def transaction method within transactions.rb). Once the app encountered this error, the same error will keep occurring (cannot recover from it) unless the app server is restarted (which reinitialize a new db connection / db object). Just wondering, for line 227 in transactions.rb: _'if opts[:savepoint] != false && (stack = trans(conn)[:savepoints]) && stack.last[:auto_savepoint]', may we have a nil safe check on the 'stack' and raise a Sequel::Error (similar to the error raised for 'cannot set :retry_on options if you are already inside a transaction') to help use catching the error ? Thank you. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Just wondering whether the following method in Sequel::Database class (transactions.rb):
is protected against multiple threads ?
The '_trans(conn)' is protected against multiple threads as 'Sequel.synchronize{@Transactions[conn]}', but once the threads have gained access to the current transactions of the connection, is it possible that 2 threads could possibly access the [:savepoints] at the same time and the transaction_finished? method could return as not finished and Sequel.synchronize{@transactions.delete(conn)} won't be executed (and there will be undefined method [] for nil class error on the following line:
if opts[:savepoint] != false && (stack = _trans(conn)[:savepoints]) && stack.last[:auto_savepoint] line 221 transactions.rb) ?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions