Page MenuHomePhabricator

If replica is lagged, duplicate entry exception in cu_useragent_clienthints_map
Closed, ResolvedPublicBUG REPORT

Description

What is the problem?

If the replica database is lagging and if I submit the same client hints for a revision twice, I see the exception:

Error: exception of type Wikimedia\\Rdbms\\DBQueryError: Error 1062: Duplicate entry '532-0-1662' for key 'PRIMARY'\nFunction: MediaWiki\\CheckUser\\Services\\UserAgentClientHintsManager::insertMappingRows\nQuery: INSERT INTO `cu_useragent_clienthints_map` (uachm_uach_id,uachm_reference_type,uachm_reference_id) VALUES (532,0,1662),(34,0,1662),(35,0,1662),(36,0,1662),(14,0,1662),(15,0,1662),(16,0,1662)
...

I guess this is the same as is happening in T342826 but for the other client hints table.

This bug is slightly different to T344787 and T344875 because I have only been able to reproduce it when the replica is lagged.

Steps to reproduce problem
  1. Setup a local wiki with replication lag (see https://www.mediawiki.org/wiki/User:DWalden_(WMF)/Simulating_database_replication_lag or T342826)
  2. Make an edit in Firefox
  3. Find out the revision ID of the edit you just made
  4. Run this command to make two client hints requests in a row. Replace <rev id> with the revision ID you just made:
for i in {1..2}; do curl 'http://localhost:8080/w/rest.php/checkuser/v0/useragent-clienthints/revision/<rev id>' -H 'Content-Type: application/json' --data-raw '{"architecture": "", "bitness": "129", "brands": [{"brand": "Not.A/Brand", "version": "8"}, {"brand": "Chromium", "version": "114"}], "fullVersionList": [{"brand": "Not.A/Brand", "version": "8.0.0.0"}], "mobile": false, "model": "", "platform": "Linux", "platformVersion": "5.10.0"}'; done

Expected behavior: Either a success message or Client hint mappings already exist for revision <rev id>.
Observed behavior: The above exception.

Environment

Wiki(s): MediaWiki 1.41.0-alpha (ad2734f) 06:12, 29 August 2023. CheckUser 2.5 (999417f) 13:47, 28 August 2023.

Event Timeline

Dreamy_Jazz subscribed.

Should be fixable by changing to use INSERT IGNORE.

Change 953239 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] clienthints: Use IGNORE when inserting mapping rows

https://gerrit.wikimedia.org/r/953239

To clarify, I had looked at fixing this, but then doing that dropped out of my mind when I went to Wikimania.

Change 953239 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] clienthints: Use IGNORE when inserting mapping rows

https://gerrit.wikimedia.org/r/953239

I can no longer reproduce the exception in the description with a variety of test data.

When making the client hints request the second time (before the replica lag has caught up) I see the same success message I saw in the first request.

Test environment: local docker mysql CheckUser 2.5 (dfa9b11) 19:20, 4 September 2023.