BIND 10 #326: Race condition in first startup (when database file does not exist)

BIND 10 Development do-not-reply at isc.org
Thu Jul 14 15:42:08 UTC 2011


#326: Race condition in first startup (when database file does not exist)
-------------------------------------+-------------------------------------
                   Reporter:  jelte  |                 Owner:
                       Type:         |                Status:  reopened
  defect                             |             Milestone:  Next-Sprint-
                   Priority:  major  |  Proposed
                  Component:  data   |            Resolution:
  source                             |             Sensitive:  0
                   Keywords:         |           Sub-Project:  DNS
            Defect Severity:         |  Estimated Difficulty:  0.0
  Medium                             |           Total Hours:  0
Feature Depending on Ticket:         |
        Add Hours to Ticket:  0      |
                  Internal?:  0      |
-------------------------------------+-------------------------------------
Changes (by shane):

 * milestone:   => Next-Sprint-Proposed


Comment:

 The problem here arises in sqlite3_ds.py:

 {{{
     # Does the database exist yet?  If not, create it.
     try:
         cur.execute("SELECT version FROM schema_version")
         row = cur.fetchone()
     except:
         create(cur)
         conn.commit()
         row = [1]
 }}}

 This code causes problems if multiple programs execute the create()
 function at the same time.

 Three changes should probably be made:

   1. We should not catch all exceptions, but rather only the
 sqlite3.OperationalError exception, and we should verify that the
 exception is "no such table".
   1. We should not perform our table creation in an exception handler,
 rather we should set a flag and create the table outside of the exception
 handler.
   1. If we have to create the tables, then we need to:
     a. start with a BEGIN EXCLUSIVE TRANSACTION statement
 (http://www.sqlite.org/lang_transaction.html)
     a. check again that the table does not exist
     a. either do nothing and ROLLBACK (if the table does exist) or create
 the tables then COMMIT (if the tables still do not exist)

 I'm not 100% sure, but this seems to be the case.

-- 
Ticket URL: <http://bind10.isc.org/ticket/326#comment:4>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list