Forum OpenACS Q&A: Response to db_foreach in transactions

Collapse
Posted by Andrew Grumet on
Just as a heads up to future bboard searchers, this sort of db handle confusion can also result in deadlocks:
db_transaction {

    db_dml ins { insert into foo ... }

    db_foreach cur { select from ... } {

        db_dml upd { update foo ... }

    }
}
The problem here is that the insert "ins" and update "upd" are running in separate transactions as a result of using different handles. The update will wait for the insert to complete, causing the db_foreach to hang. But the insert won't complete until the db_foreach completes, so you wait forever.

See also bug 41 on the dotlrn bug tracker.