Page MenuHomePhabricator

"Duplicate entry '0' for key 'behavior'"
Closed, ResolvedPublic1 Estimated Story PointsBUG REPORT

Description

What is the problem?

Some combinations of data lead to the below exception:

/srv/service/node_modules/mariadb/lib/misc/errors.js:61
  return new SqlError(msg, sql, fatal, info, sqlState, errno, additionalStack, addHeader);
         ^

SqlError: (conn=1543, no: 1062, SQLState: 23000) Duplicate entry '0' for key 'behavior'
sql: INSERT INTO behaviors (behavior) VALUES (?); - parameters:[false]
    at Object.module.exports.createError (/srv/service/node_modules/mariadb/lib/misc/errors.js:61:10)
    at PacketNodeEncoded.readError (/srv/service/node_modules/mariadb/lib/io/packet.js:511:19)
    at Query.readResponsePacket (/srv/service/node_modules/mariadb/lib/cmd/resultset.js:46:28)
    at PacketInputStream.receivePacketBasic (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  text: "Duplicate entry '0' for key 'behavior'",
  sql: 'INSERT INTO behaviors (behavior) VALUES (?); - parameters:[false]',
  fatal: false,
  errno: 1062,
  sqlState: '23000',
  code: 'ER_DUP_ENTRY'
}
Steps to reproduce problem
  1. Save the JSON from "Reproduction data" below as a .gz file (e.g. behaviours_duplicate_reprod.json.gz) into the ipoid/tmp directory
  2. If necessary, start up docker in the ipoid directory (e.g. docker compose up -d)
  3. Initialise the database: docker compose exec web node init-db.js
  4. Run this command: docker compose exec -e FEED_PATH=./tmp/behaviours_duplicate_reprod.json.gz web node import-data.js
Environment

ipoid commit deed45d61626f952ce8b9365e12e8bd98703fa17

Reproduction data
{"as": {"number": -16121, "Organization": "\u00dd"}, "client": {"behaviors": [false, false, null, "\ud8d2\udc4a", null, 109, 22559, true, 8131, "\u00b0"], "concentration": {}, "count": 4988, "countries": 11367, "proxies": ["\u00e5", null, null, true, false, 5, "\u0093", null], "spread": "\u0084", "types": ["DESKTOP", "HEADLESS", "HEADLESS", "DESKTOP"]}, "infrastructure": -8911, "location": {"state": 6912, "city": false, "country": "\u00b4\u00dd"}, "organization": false, "risks": ["GEO_MISMATCH"], "services": [], "tunnels": [{"anonymous": "\udacf\udc4f", "entries": ["\ud8fc\ude67\u000ex\u0012", null], "operator": 934011972, "type": ""}, {"anonymous": false, "entries": [41633035075126012038491746581005889092, null, null, "g\ud841\udcacZ\u00f8<", true, "R", "\ud997\udc55\ud929\udc3d\u00c9"], "operator": "\u0080", "type": "<\u00e4\u00a1\u00e8"}, {"anonymous": -103, "entries": [], "operator": "\ru\uda6b\udf21\u0082\u00b58\u00efx\u2333\u00d7\u00f5\u0083\ud886\udd00r\u0098\u00f7", "type": ""}], "ip": "fb13ef4c-4a5f-4333-b0a9-fb2ea67ad0ff"}
{"as": {"Organization": "\u00a0", "number": ">"}, "client": {"behaviors": [false, true, 1, 26], "concentration": {"density": null}, "count": true, "countries": true, "proxies": [], "spread": "C", "types": ["HEADLESS", "DESKTOP", "MOBILE", "MOBILE", "MOBILE"]}, "infrastructure": null, "location": {"state": "S", "city": 2, "country": "\u00f8"}, "organization": 112, "risks": ["WEB_SCRAPING", "GEO_MISMATCH"], "services": [-350, "", 32, 1573, -2210, null], "tunnels": [{"anonymous": 18057, "entries": [-15022], "operator": false, "type": true}, {"anonymous": "\u00b4\u001e\udae7\udd569\u00b9", "entries": [], "operator": -1579573877, "type": "\udb29\uddb0"}, {"anonymous": "B", "entries": [], "operator": 2538, "type": "6\u00b6\u0081\u00b7"}, {"anonymous": true, "entries": [], "operator": -762486195, "type": false}, {"anonymous": null, "entries": [null, null, -1457, "*", null, 18831, "\u00fc", true, null, null, null, "\"", "\uda15\udfde\u0005+\u0086\u00d1\ud8b4\udc68d<u\ud952\udcd2|\ud932\ude28", 126, null], "operator": "l", "type": "\u00f0"}], "ip": "45d99abe-cbb9-425a-9603-7f595c737ba4"}

Event Timeline

I'm getting errors mainly for the Tunnels table, but not the one mentioned in this ticket.
With reprod data from T34166 or T339204-2 (second comment from Dom), I do not get the error.
I conclude the issue related to the behaviors table has been fixed since the patch was created.

The results from testing with different reprod data shared in various IPoid tickets (also seen in the investigation on T340178)

  • With reprod data from this patch - ER_TRUNCATED_WRONG_VALUE_FOR_FIELD | Incorrect integer value: '?' for column test.tunnels.anonymous, tunnels table
  • With reprod data from T340178 - 'ER_WARN_DATA_OUT_OF_RANGE' | Out of range value for column 'anonymous', tunnels table
  • With reprod data from T339324 - ER_DATA_TOO_LONG | for the tunnels table "Data too long for column 'type'", tunnels table [bug addressed in T339324]
STran subscribed.

The error comes from this line in the schema that foces behavior to be unique:

behavior VARBINARY(64) UNIQUE,

And is caused by passing along the false value for a behavior which was discovered as part of T339204#9010746 (The false value would return a false positive from the db, allowing the code to continue executing and trying to re-insert the false value again) and fixed in https://gitlab.wikimedia.org/repos/mediawiki/services/ipoid/-/merge_requests/32 (stop any false values from being inserted into the db).

@AGueyte I think I am seeing this bug again. It is happening for data that should be considered valid.

/srv/service/node_modules/mariadb/lib/misc/errors.js:61
  return new SqlError(msg, sql, fatal, info, sqlState, errno, additionalStack, addHeader);
         ^

SqlError: (conn=915, no: 1062, SQLState: 23000) Duplicate entry 's' for key 'behavior'
sql: INSERT INTO behaviors (behavior) VALUES (?); - parameters:['s']
    at Object.module.exports.createError (/srv/service/node_modules/mariadb/lib/misc/errors.js:61:10)
    at PacketNodeEncoded.readError (/srv/service/node_modules/mariadb/lib/io/packet.js:511:19)
    at Query.readResponsePacket (/srv/service/node_modules/mariadb/lib/cmd/resultset.js:46:28)
    at PacketInputStream.receivePacketBasic (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/srv/service/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  text: "Duplicate entry 's' for key 'behavior'",
  sql: "INSERT INTO behaviors (behavior) VALUES (?); - parameters:['s']",
  fatal: false,
  errno: 1062,
  sqlState: '23000',
  code: 'ER_DUP_ENTRY'
}

I believe the entry it is falling over on is:

{"organization": null, "client": {"types": ["MOBILE", "HEADLESS", "DESKTOP", "IOT", "IOT", "DESKTOP", "MOBILE", "MOBILE", "DESKTOP"], "spread": null, "behaviors": ["RdhZsDneuUy", "ldUdpOMLRBEwBnlTknov", "mSQwyPfbBBDMc", "s", "JDAIiIJBTlUMgab", "cgRA", "tg", "dswmtlgMCyAHa", "s"], "concentration": {"state": false, "geohash": null, "country": false, "city": null, "density": null}, "countries": 25031}, "as": {"number": null}, "risks": null, "services": true, "infrastructure": null, "tunnels": [{"type": "P", "anonymous": false}, {"type": true, "exits": null, "entries": false, "operator": null}, {"type": false}, {"type": "", "exits": null}, {"type": null, "operator": false, "exits": ["NNIkTdMevT", "nrupClE", "J", "xspTX", "KJ", "ezQmJAj", "SobReIZ", "ZSff", "SW", "yufVGdLPzi", "NXsOlJpklg"], "entries": false, "anonymous": true}], "location": {"country": "hME", "city": "BbFYvvRxr", "state": false}, "ip": "df72d69a-5330-471d-9038-9473b65db288"}

Another example, but here it seems the conflicting duplicate entries are from different entries in the JSON file:

{"infrastructure": null, "tunnels": [], "organization": false, "as": {}, "client": {"behaviors": ["L", "LXBWDMUZqx", "G", "v", "pHZMLPdQzbpXgqqTWrY", "lrQsd", "XG", "C", "LoMRviyDTrickzdtwUWQilW", "l", "iRY", "XPakyp", "sNODys", "yqDhptB", "mix", "kJqfJxq", "HkKXGTfQqOYL", "hUOYNoAfwX", "POldXRuoLfPWovdfOYmy", "JHDMr", "Etm", "ssKGIJujBBWiRwZ", "U", "HI", "UetSdozt"], "count": false, "concentration": {"state": "FIdj"}}, "location": {}, "ip": "389c6fc5-eef1-4dc5-bdaa-0a50021f9066"}
{"infrastructure": null, "tunnels": [], "organization": null, "as": {}, "client": {"behaviors": ["L", "LXBWDMUZqx", "G", "v", "pHZMLPdQzbpXgqqTWrY", "lrQsd", "XG", "C", "LoMRviyDTrickzdtwUWQilW", "l", "iRY", "XPakyp", "sNODys", "yqDhptB", "mix", "kJqfJxq", "HkKXGTfQqOYL", "hUOYNoAfwX", "POldXRuoLfPWovdfOYmy", "JHDMr", "Etm", "ssKGIJujBBWiRwZ", "U", "HI", "UetSdozt"], "count": false, "concentration": {"state": "FIdj"}}, "location": {}, "ip": "aec62c9b-4ba1-4ed5-9377-ff1ff4b7d551"}

dom_walden mentioned this in Unknown Object (Task).Jul 27 2023, 1:37 PM