Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84070

Race conditions when writing to user preferences in two requests

XMLWordPrintable

      Two processes writing to the same user preference for the first time can result in a db exception:

      NOTICE: PHP message: Default exception handler: Error writing to database Debug: ERROR:  duplicate key value violates unique constraint "mdl_userpref_usenam_uix""
      DETAIL:  Key (userid, name)=(2, tool_sessbreak_var1) already exists."
      INSERT INTO mdl_user_preferences (userid,name,value) VALUES($1,$2,$3) RETURNING id"
      [array ("
        'userid' => '2',"
        'name' => 'tool_sessbreak_var1',"
        'value' => '46',"
      )]"
      Error code: dmlwriteexception"
      * line 500 of /lib/dml/moodle_database.php: dml_write_exception thrown"
      * line 346 of /lib/dml/moodle_read_replica_trait.php: call to moodle_database->query_end()"
      * line 358 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->read_replica_query_end()"
      * line 1149 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()"
      * line 1197 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()"
      * line 1537 of /lib/moodlelib.php: call to pgsql_native_moodle_database->insert_recor..."

      This is solved easily with a transaction, it would also be better solved via MDL-70974

            brendanheywood Brendan Heywood
            brendanheywood Brendan Heywood
            Benjamin Walker Benjamin Walker
            Huong Nguyen Huong Nguyen
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 49 minutes
                1h 49m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.