提交 f7e126be 编写于 作者: R Ryuta Kamizono

Don't refer `@transaction_state` directly

Since 8180c396, remaining transaction state is cleared in
`force_clear_transaction_record_state` to less work
`sync_with_transaction_state`. But it caused a race condition that
`@transaction_state` would be cleared by other threads if the state is
finalized.

To work as before, snapshot `@transaction_state` to local variable not
to refer `@transaction_state` directly.

Fixes #35983.
上级 60afbfff
......@@ -472,13 +472,13 @@ def has_transactional_callbacks?
# the TransactionState, and rolls back or commits the Active Record object
# as appropriate.
def sync_with_transaction_state
if @transaction_state && @transaction_state.finalized?
if @transaction_state.fully_committed?
if (transaction_state = @transaction_state)&.finalized?
if transaction_state.fully_committed?
force_clear_transaction_record_state
elsif @transaction_state.committed?
elsif transaction_state.committed?
clear_transaction_record_state
elsif @transaction_state.rolledback?
force_restore_state = @transaction_state.fully_rolledback?
elsif transaction_state.rolledback?
force_restore_state = transaction_state.fully_rolledback?
restore_transaction_record_state(force_restore_state)
clear_transaction_record_state
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册