Ad Widget

Collapse

possible race condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alj
    Senior Member
    • Aug 2006
    • 188

    #1

    possible race condition

    from include/db.inc.php
    ---------------------------------------
    DBexecute("update ids set nextid=nextid+1 where
    nodeid=$nodeid and table_name='$table' and field_name='$field'");

    $row = DBfetch(DBselect("select nextid from ids
    where nodeid=$nodeid and table_name='$table' and field_name='$field'"));
    ---------------------------------------
    If 2 people simultaneoulsy add some element (like graph) it can cause race condition, ids will get incremented 2 times then both users will get the same ID which was incremented 2 times -> database inconsistency as result. You could lock the table between increment and select, but why make thinks so complicated?
    Why can't you use autoincrement indexes on all tables?
    You dont need ids table at all then, and since operation will be atomic you will avoid race condition without locking.
  • Alexei
    Founder, CEO
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2004
    • 5654

    #2
    Originally posted by alj
    If 2 people simultaneoulsy add some element (like graph) it can cause race condition, ids will get incremented 2 times then both users will get the same ID which was incremented 2 times -> database inconsistency as result.
    It is impossible. Please follow logic of the whole get_dbid().
    Alexei Vladishev
    Creator of Zabbix, Product manager
    New York | Tokyo | Riga
    My Twitter

    Comment

    Working...