Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In D7, this code:
var_dump(lock_acquire('x'));
var_dump(lock_acquire('x'));
returns
bool(true)
bool(true)
.
In D6 it returns
bool(true)
bool(false)
This is due to a bug in the backport.
Comment | File | Size | Author |
---|---|---|---|
#9 | lock_acquire-2.patch | 697 bytes | c960657 |
#7 | lock_acquire-1.patch | 1.25 KB | c960657 |
lock_acquire-D6.patch | 1.25 KB | c960657 | |
Comments
Comment #1
c960657 CreditAttribution: c960657 commentedComment #2
drewish CreditAttribution: drewish commentedRan into this issue as well. The patch corrects the problem.
Comment #3
Gábor HojtsyPlease provide a more detailed explanation of what is going on and more reviewers if possible. Thanks!
Comment #4
c960657 CreditAttribution: c960657 commentedThe problem is that the return value from db_query("UPDATE ... WHERE ...") is passed on to db_result() in order to see if any rows matched the WHERE clause of the query.
This is wrong. db_query("UPDATE ...") always returns TRUE, unless an error occurred (note that this is not described in the documentation of db_query()).
The proper way to see if any rows where matched by the WHERE clause of an UPDATE query is to use db_affected_rows(). This is what the patch does. If no rows where affected, it means that our lock is no longer in the database table and thus cannot be extended.
Comment #5
mgriego CreditAttribution: mgriego commentedSeeing the same thing here when we try to extend an unexpired lock. As c960657 said, It is not proper to use db_result() on a db_query() return value when an UPDATE query is used. For MySQL systems, the result of mysql_query() where an UPDATE query is issued is simply TRUE or FALSE, not a resource as db_result() expects. FALSE only happens on error, and an UPDATE that doesn't update any rows is not an error, so the db_affected_rows() call in the supplied patch is the proper way of handling this.
From what I can tell, pg_query() returns a result resource regardless of the query type issued, so, if the locking implementation was initially written and tested against Postgres, then that may be why this wasn't caught before. We (and I'm sure most of the people using Drupal), however, use MySQL.
Comment #6
mgriego CreditAttribution: mgriego commentedWe are running this patch in our production environment now without issues.
Comment #7
c960657 CreditAttribution: c960657 commentedRenaming patch to force test bot to pick it up.
Comment #9
c960657 CreditAttribution: c960657 commentedReroll (identical patch, just created with Git instead of CVS).
Comment #10
Gábor HojtsyThanks for the extra testing and details, committed and pushed.