Transactions: fix waiting logic