Was using a key generator based upon the code in uc_product_keys_sample.module and got this error when trying to complete an order. I tracked this down to the routine: _uc_product_keys_sample_db_allocate_licenses.

In this routine you are calling db_lock_table('uc_product_keys') and db_unlock_tables(); In Drupal 6, modules are no longer supposed to use the LOCK TABLES permission.

When I removed these lines then the error went away. Since this is just an example module and it's really up to the developer to handle locking issues like this, I suggest removing these lines from the sample module.

Comments

freixas’s picture

Assigned: Unassigned » freixas
Status: Active » Postponed (maintainer needs more info)

Where did you find the documentation that says that I shouldn't lock tables in D6? I just looked this function up in the API and don't see any deprecation notes. I did find some discussions about removing table locking in the Drupal core, but that's a different issue.

Also, you can remove the calls and get rid of the error, but that doesn't mean you won't have a race condition. Do you have a viable alternative?

Is it possible you don't have LOCK TABLES permission?

Unless I can find out more, I won't remove the locks. I'd love to use transactions instead, but I don't know of any transaction support in Drupal other than db_lock_table().

mpotter’s picture

I'll have to do some more searching to track down the link to the issues about locking tables. LOCK TABLES used to be a requirement in D5, but this requirement was lifted in core, and module developers were encouraged to remove their own dependence upon LOCK TABLES. But I didn't save the link to the topic where I read that.

In my case, I *do* have the LOCK TABLES permission and I have no idea why I get this error. For now my site doesn't get nearly enough traffic to cause any race conditions. Unfortunately I just don't know enough about this issue to really suggest an alternative. When I was trying to track down this problem, I was searching for the above error message with the Drupal watchdog table:

Table 'watchdog' was not locked with LOCK TABLES query

and somewhere in those search results is where I read about getting rid of the db_lock_table call.

freixas’s picture

Status: Postponed (maintainer needs more info) » Needs review

Based on #788686: Not locking the right table in _uc_product_keys_sample_db_allocate_licenses(), I have changed the locked table from uc_product_keys to uc_product_keys_sequences.

Rognon and mpotter: Could you please let me know if this fixes your problems? If so, I will create a 1.0 release that includes this fix.

The fix is included in any dev release dated 5/4/10 or later.

Rognon’s picture

I confirm that the dev release dated 5/4/10 works for me.

freixas’s picture

Status: Needs review » Fixed

Thank you, Rognon. I've marked this fixed and will shortly release v1.0.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.