Bug #5622


Captive Portal database handling can reset the DB while it is locked when it should wait instead

Added by Jim Pingle almost 6 years ago. Updated over 5 years ago.

Captive Portal
Target version:
Start date:
Due date:
% Done:


Estimated time:
Plus Target Version:
Release Notes:
Affected Version:
Affected Architecture:


From a user-submitted message:


etc/inc/ will reinitialize the
database(-file) if the file exists, but an error happens during query
execution. Because this can be a simple database lock (e.g. by minicron
job to prune old entries, or by a login happening at the same time),
chances are relatively that this happens sooner or later.

The relevant loc is


Possible "solutions":
1) give opendb a "retry" like it already does e.g. in

if (! $DB->exec($createquery)) {
  captiveportal_syslog("Error during table {$cpzone} creation. Error message: {$DB->lastErrorMsg()}. Trying again.");
  # sleep (0.1) // Did I mention I dont know php much?
  if (! $DB->exec ...
    captiveportal_syslog("Still error during table {$cpzone} creation.... Resetting");

2) Explicitely check whether we ran into a lock and retry. This should
be done using $DB->lastErrorCode()
a) do retry x times/seconds or
b) wait to get the lock forever.

Both approaches will not forever solve the issue, but drastically
lowering the chances that we have "pass-throughs" without being able to
easily spot them via the CP pages.

If the DB is reset while users are active, IPFW rules are left in place which allow some users to inadvertently retain access longer than they should. If the DB is reset the IPFW tables should be reset as well, but it looks like it should also wait a brief period for the lock to clear before resetting if it's locked and not actually corrupt.

Actions #1

Updated by Chris Buechler almost 6 years ago

  • Status changed from New to Confirmed

re: cleaning up ipfw rules after the database is reinitialized, the reinit=true doesn't exist as it used to in 2.0x.

That was removed as part of the graceful reloading of CP, but needs to come back for the database re-initialization scenario to ensure nothing's left behind in the tables.

Actions #2

Updated by Jose Carlos Bilhega almost 6 years ago

I running about 2 days without any erros ( crashes or locking logs ) with just the use of busytimeout added on the line 1430:

if (! $DB->exec($createquery)) {


I hope this is a good solution.

Actions #3

Updated by Chris Buechler almost 6 years ago

  • Status changed from Confirmed to Feedback
  • Assignee set to Chris Buechler

believe this to be fixed, leaving for additional feedback.

Actions #4

Updated by Chris Buechler over 5 years ago

  • Status changed from Feedback to Resolved



Also available in: Atom PDF